diff --git a/.gitignore b/.gitignore index 7dd921057..c7c5cb351 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,6 @@ VSWorkspaceState.json .idea/ # ReSharper Settings -*.DotSettings *.DotSettings.user @@ -408,4 +407,3 @@ VSCodeExtension/ncqa-cql-engine-workspace/test/*/*/results/*.json /Demo/**/Resources/*.* #remove global.json for testing dotnet sdk updates global.json -/Cql/CqlSdkPrototype/generated diff --git a/Cql-Sdk-All.sln b/Cql-Sdk-All.sln index 967beb973..7feb9abfd 100644 --- a/Cql-Sdk-All.sln +++ b/Cql-Sdk-All.sln @@ -123,10 +123,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "50 CLI Packaging Tools", "5 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CqlSdkPrototype", "Cql\CqlSdkPrototype\CqlSdkPrototype.csproj", "{67D0864B-5682-E701-002E-587BEB5DA60F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "Demo\API\API.csproj", "{C667CF52-C1E9-41C0-9723-C2DC46C21B46}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{360E03FF-3AA0-4619-ACCA-93E78265F6DD}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "60 Public API Prototype", "60 Public API Prototype", "{A474C299-9204-4344-B248-1F2FB2CF1830}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CqlApiExamples", "Demo\CqlApiExamples\CqlApiExamples.csproj", "{6165AC8C-733D-9679-5A47-978E61B742FB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cql", "Demo\Cql\Cql.csproj", "{A50AA2A0-7868-73A7-2E02-E810842576F9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -265,10 +269,14 @@ Global {67D0864B-5682-E701-002E-587BEB5DA60F}.Debug|Any CPU.Build.0 = Debug|Any CPU {67D0864B-5682-E701-002E-587BEB5DA60F}.Release|Any CPU.ActiveCfg = Release|Any CPU {67D0864B-5682-E701-002E-587BEB5DA60F}.Release|Any CPU.Build.0 = Release|Any CPU - {C667CF52-C1E9-41C0-9723-C2DC46C21B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C667CF52-C1E9-41C0-9723-C2DC46C21B46}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C667CF52-C1E9-41C0-9723-C2DC46C21B46}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C667CF52-C1E9-41C0-9723-C2DC46C21B46}.Release|Any CPU.Build.0 = Release|Any CPU + {6165AC8C-733D-9679-5A47-978E61B742FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6165AC8C-733D-9679-5A47-978E61B742FB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6165AC8C-733D-9679-5A47-978E61B742FB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6165AC8C-733D-9679-5A47-978E61B742FB}.Release|Any CPU.Build.0 = Release|Any CPU + {A50AA2A0-7868-73A7-2E02-E810842576F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A50AA2A0-7868-73A7-2E02-E810842576F9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A50AA2A0-7868-73A7-2E02-E810842576F9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A50AA2A0-7868-73A7-2E02-E810842576F9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -288,7 +296,7 @@ Global {A252DF59-263B-46D9-A1E4-48E16D8D0DEC} = {F2ADD1CA-E231-4E88-B0EE-5C6885422629} {399B718D-41C6-4DD9-A7E3-B9758CAAEB89} = {F2ADD1CA-E231-4E88-B0EE-5C6885422629} {02DCA9CB-92A1-47C9-BF40-97DDD56DEFF3} = {D0F1B9D3-DD8C-4F25-B7AF-0C2EB4E17AC3} - {8FF55BB5-6004-4461-B8EA-19E9F41B970B} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} + {8FF55BB5-6004-4461-B8EA-19E9F41B970B} = {F2ADD1CA-E231-4E88-B0EE-5C6885422629} {50590B39-F376-4E96-92CF-67F84C149E86} = {97D67019-21A7-4591-A216-1B76BD0E68A4} {FEF0C134-505D-4206-8630-569A6762F787} = {295F5788-3893-4794-A574-4B0A75A3A4BC} {A7111722-6C8F-42AA-8CDD-732D34FB678A} = {85401759-2C64-414D-9882-4DB1EA41C2ED} @@ -306,7 +314,7 @@ Global {AF223BDF-576D-45FD-9A33-483BAFE1BB75} = {A2259B13-A115-4EA3-9DFB-5411DB88EA6F} {BF2C14B3-EF9B-4BE9-A843-EAA05368BD5A} = {A2259B13-A115-4EA3-9DFB-5411DB88EA6F} {F2ADD1CA-E231-4E88-B0EE-5C6885422629} = {4B5D75F5-E2FC-4CCB-90EF-6DC4A0193032} - {BF5D524C-0582-4471-BC79-B04B2D8DFCDB} = {295F5788-3893-4794-A574-4B0A75A3A4BC} + {BF5D524C-0582-4471-BC79-B04B2D8DFCDB} = {360E03FF-3AA0-4619-ACCA-93E78265F6DD} {0E5F5704-5289-4C65-AD4E-364CD5F60C44} = {D33B7DF4-8AC5-47D1-A782-AC5078FFDEC7} {2929117D-FB33-4BD6-8F20-4B623C114438} = {0E5F5704-5289-4C65-AD4E-364CD5F60C44} {1AF2E4B2-99C5-4678-B926-D224CC83A8F7} = {D33B7DF4-8AC5-47D1-A782-AC5078FFDEC7} @@ -317,11 +325,13 @@ Global {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} = {B00E560D-AE0C-48E1-9013-57115AF05F41} {85401759-2C64-414D-9882-4DB1EA41C2ED} = {B00E560D-AE0C-48E1-9013-57115AF05F41} {295F5788-3893-4794-A574-4B0A75A3A4BC} = {4B5D75F5-E2FC-4CCB-90EF-6DC4A0193032} - {67D0864B-5682-E701-002E-587BEB5DA60F} = {295F5788-3893-4794-A574-4B0A75A3A4BC} - {C667CF52-C1E9-41C0-9723-C2DC46C21B46} = {7D787B73-D44A-4B65-B83F-4AF4A752F26C} + {67D0864B-5682-E701-002E-587BEB5DA60F} = {A474C299-9204-4344-B248-1F2FB2CF1830} + {A474C299-9204-4344-B248-1F2FB2CF1830} = {4B5D75F5-E2FC-4CCB-90EF-6DC4A0193032} + {6165AC8C-733D-9679-5A47-978E61B742FB} = {A474C299-9204-4344-B248-1F2FB2CF1830} + {A50AA2A0-7868-73A7-2E02-E810842576F9} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - FileExplorer = |build\|docs\|LibrarySets\|submodules\Firely.Cql.Sdk.Integration.Runner\NodeJsUtils\ SolutionGuid = {366252DE-C2FB-4EAC-96EE-22210BD43DE2} + FileExplorer = |build\|docs\|LibrarySets\|submodules\Firely.Cql.Sdk.Integration.Runner\NodeJsUtils\ EndGlobalSection EndGlobal diff --git a/Cql/CodeGeneration.NET/AssemblyData.cs b/Cql/CodeGeneration.NET/AssemblyBinary.cs similarity index 68% rename from Cql/CodeGeneration.NET/AssemblyData.cs rename to Cql/CodeGeneration.NET/AssemblyBinary.cs index 1e0eecfcc..872bfcfe2 100644 --- a/Cql/CodeGeneration.NET/AssemblyData.cs +++ b/Cql/CodeGeneration.NET/AssemblyBinary.cs @@ -9,16 +9,16 @@ namespace Hl7.Cql.CodeGeneration.NET; /// -/// Stores information about a dynamically generated assembly. +/// Contains the binary data for an assembly, and optionally its debug symbols. /// /// This assembly's binary data. -/// The assembly's debug symbols in binary data. -public record AssemblyData( +/// The assembly's debug symbols. +public record AssemblyBinary( byte[]? AssemblyBytes, byte[]? DebugSymbolsBytes = null) { /// - /// An empty instance of . + /// An empty instance of . /// - public static AssemblyData Default { get; } = new(null!, null!); + public static AssemblyBinary Default { get; } = new(null!, null!); } \ No newline at end of file diff --git a/Cql/CodeGeneration.NET/AssemblyDataExtensions.cs b/Cql/CodeGeneration.NET/AssemblyBinaryExtensions.cs similarity index 81% rename from Cql/CodeGeneration.NET/AssemblyDataExtensions.cs rename to Cql/CodeGeneration.NET/AssemblyBinaryExtensions.cs index fd5b5b192..f819e2346 100644 --- a/Cql/CodeGeneration.NET/AssemblyDataExtensions.cs +++ b/Cql/CodeGeneration.NET/AssemblyBinaryExtensions.cs @@ -9,9 +9,9 @@ namespace Hl7.Cql.CodeGeneration.NET; /// -/// Extension methods for . +/// Extension methods for . /// -public static class AssemblyDataExtensions +public static class AssemblyBinaryExtensions { /// /// Writes the assembly data to disk. @@ -19,11 +19,11 @@ public static class AssemblyDataExtensions /// The assembly data to write. /// The path to write the assembly to. /// The path to write the debug symbols to. - public static TAssemblyData SaveToFiles( - this TAssemblyData self, + public static TAssemblyBinary SaveToFile( + this TAssemblyBinary self, FileInfo? assemblyFile = null, FileInfo? debugSymbolsFile = null) - where TAssemblyData : AssemblyData + where TAssemblyBinary : AssemblyBinary { if (assemblyFile is { } asmFile && self.AssemblyBytes is { Length: > 0 } asmBytes) { @@ -43,16 +43,16 @@ public static TAssemblyData SaveToFiles( /// /// Loads assembly data from files and returns a new instance. /// - /// + /// /// The assembly data to start from /// The path to read the assembly from. /// The path to read the debug symbols from. /// - public static TAssemblyData LoadFromFiles( - this TAssemblyData self, + public static TAssemblyBinary LoadFromFile( + this TAssemblyBinary self, FileInfo? assemblyFile = null, FileInfo? debugSymbolsFile = null) - where TAssemblyData : AssemblyData + where TAssemblyBinary : AssemblyBinary { var assemblyBytes = assemblyFile is {} f1 ? File.ReadAllBytes(f1.FullName) : self.AssemblyBytes; var debugSymbolsBytes = debugSymbolsFile is {} f2 ? File.ReadAllBytes(f2.FullName) : self.DebugSymbolsBytes; diff --git a/Cql/CodeGeneration.NET/AssemblyDataWithSourceCode.cs b/Cql/CodeGeneration.NET/AssemblyBinaryWithSourceCode.cs similarity index 82% rename from Cql/CodeGeneration.NET/AssemblyDataWithSourceCode.cs rename to Cql/CodeGeneration.NET/AssemblyBinaryWithSourceCode.cs index c2a44bdd4..2e6890bfa 100644 --- a/Cql/CodeGeneration.NET/AssemblyDataWithSourceCode.cs +++ b/Cql/CodeGeneration.NET/AssemblyBinaryWithSourceCode.cs @@ -14,24 +14,24 @@ namespace Hl7.Cql.CodeGeneration.NET; /// This assembly's binary data. /// The collection of source code files that contributed to this assembly. /// The assembly's debug symbols in binary data. -internal record AssemblyDataWithSourceCode( +internal record AssemblyBinaryWithSourceCode( byte[]? AssemblyBytes, IReadOnlyDictionary? SourceCode, - byte[]? DebugSymbolsBytes = null) : AssemblyData(AssemblyBytes, DebugSymbolsBytes) + byte[]? DebugSymbolsBytes = null) : AssemblyBinary(AssemblyBytes, DebugSymbolsBytes) { /// - /// An empty instance of . + /// An empty instance of . /// - public new static AssemblyDataWithSourceCode Default { get; } = new(null, null, null); + public new static AssemblyBinaryWithSourceCode Default { get; } = new(null, null, null); /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// This assembly's binary data. /// /// /// The assembly's debug symbols in binary data. - public AssemblyDataWithSourceCode( + public AssemblyBinaryWithSourceCode( byte[]? assemblyBytes, string? sourceCodeFileName, string? sourceCode, diff --git a/Cql/CodeGeneration.NET/AssemblyCompiler.cs b/Cql/CodeGeneration.NET/AssemblyCompiler.cs index 4fd450f27..46a595c1d 100644 --- a/Cql/CodeGeneration.NET/AssemblyCompiler.cs +++ b/Cql/CodeGeneration.NET/AssemblyCompiler.cs @@ -49,12 +49,12 @@ public AssemblyCompiler(TypeResolver typeResolver) }); } - public IEnumerable<(Library library, Func generateAssemblyDataWithSourceCode)> CompileDeferred( + public IEnumerable<(Library library, Func generateAssemblyBinaryWithSourceCode)> CompileDeferred( LibrarySet librarySet, IEnumerable<(Library Library, string CSharp)> input, AssemblyCompilerDebugInformationFormat debugInformationFormat = AssemblyCompilerDebugInformationFormat.None) { - Dictionary results = new(); + Dictionary results = new(); Assembly[] assemblyReferences = _referencesLazy.Value; foreach (var (library, cSharp) in input) yield return (library, () => @@ -74,9 +74,9 @@ private static CSharpCompilationOptions CreateCSharpCompilationOptions( sourceReferenceResolver: new SourceFileResolver(ImmutableArray.Empty, null) ); - private AssemblyDataWithSourceCode CompileNode( + private AssemblyBinaryWithSourceCode CompileNode( string librarySourceString, - Dictionary assemblies, + Dictionary assemblies, LibrarySet librarySet, Library library, IEnumerable assemblyReferences, @@ -152,7 +152,7 @@ private AssemblyDataWithSourceCode CompileNode( } var bytes = codeStream.ToArray(); var debugSymbols = pdbStream?.ToArray(); - var asmData = new AssemblyDataWithSourceCode(bytes, new Dictionary { { libraryVersionedIdentifier!, librarySourceString }}, debugSymbols); + var asmData = new AssemblyBinaryWithSourceCode(bytes, new Dictionary { { libraryVersionedIdentifier!, librarySourceString }}, debugSymbols); return asmData; } @@ -231,7 +231,7 @@ private static void AddNetCoreReferences(List metadataReferen internal static class AssemblyCompilerExtensions { - public static IEnumerable<(Library library, AssemblyDataWithSourceCode assemblyDataWithSourceCode)> Compile( + public static IEnumerable<(Library library, AssemblyBinaryWithSourceCode assemblyBinaryWithSourceCode)> Compile( this AssemblyCompiler compiler, LibrarySet librarySet, IEnumerable<(Library Library, string CSharp)> input, @@ -239,7 +239,7 @@ internal static class AssemblyCompilerExtensions { return compiler .CompileDeferred(librarySet, input, debugInformationFormat) - .Select(x => (x.library, x.generateAssemblyDataWithSourceCode())); + .Select(x => (x.library, x.generateAssemblyBinaryWithSourceCode())); } } diff --git a/Cql/CodeGeneration.NET/PublicAPI.Unshipped.txt b/Cql/CodeGeneration.NET/PublicAPI.Unshipped.txt index 511d390cd..7d49e55d5 100644 --- a/Cql/CodeGeneration.NET/PublicAPI.Unshipped.txt +++ b/Cql/CodeGeneration.NET/PublicAPI.Unshipped.txt @@ -1,26 +1,26 @@ #nullable enable +Hl7.Cql.CodeGeneration.NET.AssemblyBinary +Hl7.Cql.CodeGeneration.NET.AssemblyBinary.AssemblyBinary(byte[]? AssemblyBytes, byte[]? DebugSymbolsBytes = null) -> void +Hl7.Cql.CodeGeneration.NET.AssemblyBinary.AssemblyBinary(Hl7.Cql.CodeGeneration.NET.AssemblyBinary! original) -> void +Hl7.Cql.CodeGeneration.NET.AssemblyBinary.AssemblyBytes.get -> byte[]? +Hl7.Cql.CodeGeneration.NET.AssemblyBinary.AssemblyBytes.init -> void +Hl7.Cql.CodeGeneration.NET.AssemblyBinary.DebugSymbolsBytes.get -> byte[]? +Hl7.Cql.CodeGeneration.NET.AssemblyBinary.DebugSymbolsBytes.init -> void +Hl7.Cql.CodeGeneration.NET.AssemblyBinary.Deconstruct(out byte[]? AssemblyBytes, out byte[]? DebugSymbolsBytes) -> void Hl7.Cql.CodeGeneration.NET.AssemblyCompilerDebugInformationFormat Hl7.Cql.CodeGeneration.NET.AssemblyCompilerDebugInformationFormat.Embedded = 3 -> Hl7.Cql.CodeGeneration.NET.AssemblyCompilerDebugInformationFormat Hl7.Cql.CodeGeneration.NET.AssemblyCompilerDebugInformationFormat.None = 0 -> Hl7.Cql.CodeGeneration.NET.AssemblyCompilerDebugInformationFormat Hl7.Cql.CodeGeneration.NET.AssemblyCompilerDebugInformationFormat.PortablePdb = 2 -> Hl7.Cql.CodeGeneration.NET.AssemblyCompilerDebugInformationFormat -Hl7.Cql.CodeGeneration.NET.AssemblyData -Hl7.Cql.CodeGeneration.NET.AssemblyData.AssemblyBytes.get -> byte[]? -Hl7.Cql.CodeGeneration.NET.AssemblyData.AssemblyBytes.init -> void -Hl7.Cql.CodeGeneration.NET.AssemblyData.AssemblyData(byte[]? AssemblyBytes, byte[]? DebugSymbolsBytes = null) -> void -Hl7.Cql.CodeGeneration.NET.AssemblyData.AssemblyData(Hl7.Cql.CodeGeneration.NET.AssemblyData! original) -> void -Hl7.Cql.CodeGeneration.NET.AssemblyData.DebugSymbolsBytes.get -> byte[]? -Hl7.Cql.CodeGeneration.NET.AssemblyData.DebugSymbolsBytes.init -> void -Hl7.Cql.CodeGeneration.NET.AssemblyData.Deconstruct(out byte[]? AssemblyBytes, out byte[]? DebugSymbolsBytes) -> void -Hl7.Cql.CodeGeneration.NET.AssemblyDataExtensions -override Hl7.Cql.CodeGeneration.NET.AssemblyData.Equals(object? obj) -> bool -override Hl7.Cql.CodeGeneration.NET.AssemblyData.GetHashCode() -> int -override Hl7.Cql.CodeGeneration.NET.AssemblyData.ToString() -> string! -static Hl7.Cql.CodeGeneration.NET.AssemblyData.Default.get -> Hl7.Cql.CodeGeneration.NET.AssemblyData! -static Hl7.Cql.CodeGeneration.NET.AssemblyData.operator !=(Hl7.Cql.CodeGeneration.NET.AssemblyData? left, Hl7.Cql.CodeGeneration.NET.AssemblyData? right) -> bool -static Hl7.Cql.CodeGeneration.NET.AssemblyData.operator ==(Hl7.Cql.CodeGeneration.NET.AssemblyData? left, Hl7.Cql.CodeGeneration.NET.AssemblyData? right) -> bool -static Hl7.Cql.CodeGeneration.NET.AssemblyDataExtensions.LoadFromFiles(this TAssemblyData! self, System.IO.FileInfo? assemblyFile = null, System.IO.FileInfo? debugSymbolsFile = null) -> TAssemblyData! -static Hl7.Cql.CodeGeneration.NET.AssemblyDataExtensions.SaveToFiles(this TAssemblyData! self, System.IO.FileInfo? assemblyFile = null, System.IO.FileInfo? debugSymbolsFile = null) -> TAssemblyData! -virtual Hl7.Cql.CodeGeneration.NET.AssemblyData.$() -> Hl7.Cql.CodeGeneration.NET.AssemblyData! -virtual Hl7.Cql.CodeGeneration.NET.AssemblyData.EqualityContract.get -> System.Type! -virtual Hl7.Cql.CodeGeneration.NET.AssemblyData.Equals(Hl7.Cql.CodeGeneration.NET.AssemblyData? other) -> bool -virtual Hl7.Cql.CodeGeneration.NET.AssemblyData.PrintMembers(System.Text.StringBuilder! builder) -> bool +Hl7.Cql.CodeGeneration.NET.AssemblyBinaryExtensions +override Hl7.Cql.CodeGeneration.NET.AssemblyBinary.Equals(object? obj) -> bool +override Hl7.Cql.CodeGeneration.NET.AssemblyBinary.GetHashCode() -> int +override Hl7.Cql.CodeGeneration.NET.AssemblyBinary.ToString() -> string! +static Hl7.Cql.CodeGeneration.NET.AssemblyBinary.Default.get -> Hl7.Cql.CodeGeneration.NET.AssemblyBinary! +static Hl7.Cql.CodeGeneration.NET.AssemblyBinary.operator !=(Hl7.Cql.CodeGeneration.NET.AssemblyBinary? left, Hl7.Cql.CodeGeneration.NET.AssemblyBinary? right) -> bool +static Hl7.Cql.CodeGeneration.NET.AssemblyBinary.operator ==(Hl7.Cql.CodeGeneration.NET.AssemblyBinary? left, Hl7.Cql.CodeGeneration.NET.AssemblyBinary? right) -> bool +static Hl7.Cql.CodeGeneration.NET.AssemblyBinaryExtensions.LoadFromFile(this TAssemblyBinary! self, System.IO.FileInfo? assemblyFile = null, System.IO.FileInfo? debugSymbolsFile = null) -> TAssemblyBinary! +static Hl7.Cql.CodeGeneration.NET.AssemblyBinaryExtensions.SaveToFile(this TAssemblyBinary! self, System.IO.FileInfo? assemblyFile = null, System.IO.FileInfo? debugSymbolsFile = null) -> TAssemblyBinary! +virtual Hl7.Cql.CodeGeneration.NET.AssemblyBinary.$() -> Hl7.Cql.CodeGeneration.NET.AssemblyBinary! +virtual Hl7.Cql.CodeGeneration.NET.AssemblyBinary.EqualityContract.get -> System.Type! +virtual Hl7.Cql.CodeGeneration.NET.AssemblyBinary.Equals(Hl7.Cql.CodeGeneration.NET.AssemblyBinary? other) -> bool +virtual Hl7.Cql.CodeGeneration.NET.AssemblyBinary.PrintMembers(System.Text.StringBuilder! builder) -> bool diff --git a/Cql/CoreTests/ExpressionBuilderContextTests.cs b/Cql/CoreTests/ExpressionBuilderContextTests.cs index 148d5dba2..fab4dcd80 100644 --- a/Cql/CoreTests/ExpressionBuilderContextTests.cs +++ b/Cql/CoreTests/ExpressionBuilderContextTests.cs @@ -1,4 +1,4 @@ -using CqlSdkPrototype.Elm; +using CqlSdkPrototype.Elm.Internal; using Hl7.Cql.Abstractions; using Hl7.Cql.Compiler; using Hl7.Cql.Runtime.Hosting; @@ -13,7 +13,7 @@ public class ExpressionBuilderContextTests [TestMethod] public void Get_Property_Uses_TypeResolver() { - using var serviceProvider = ElmApiState.AddCqlCompilerServices(new ServiceCollection().AddDebugLogging()).BuildServiceProvider(validateScopes: true); + using var serviceProvider = ElmToAssemblyProcessorServices.AddCqlCompilerServices(new ServiceCollection().AddDebugLogging()).BuildServiceProvider(validateScopes: true); var property = ExpressionBuilderContext.GetProperty(typeof(MeasureReport.PopulationComponent), "id", serviceProvider.GetRequiredService())!; Assert.AreEqual(typeof(Element), property.DeclaringType); Assert.AreEqual(nameof(Element.ElementId), property.Name); diff --git a/Cql/CoreTests/ExpressionBuilderTests.cs b/Cql/CoreTests/ExpressionBuilderTests.cs index 1579f49e8..aa5964476 100644 --- a/Cql/CoreTests/ExpressionBuilderTests.cs +++ b/Cql/CoreTests/ExpressionBuilderTests.cs @@ -1,14 +1,14 @@ using Hl7.Fhir.Model; -using CqlSdkPrototype.Elm; using Hl7.Cql.Compiler; using Hl7.Cql.Runtime.Hosting; +using CqlSdkPrototype.Elm.Internal; namespace CoreTests { [TestClass] public class LibraryExpressionBuilderTests { - private static ServiceProvider BuildServiceProvider() => ElmApiState.AddCqlCompilerServices(new ServiceCollection().AddDebugLogging()).BuildServiceProvider(validateScopes: true); + private static ServiceProvider BuildServiceProvider() => ElmToAssemblyProcessorServices.AddCqlCompilerServices(new ServiceCollection().AddDebugLogging()).BuildServiceProvider(validateScopes: true); [TestMethod] public void AggregateQueries_1_0_0() diff --git a/Cql/CoreTests/RuntimeApiTests.cs b/Cql/CoreTests/FluentInvocationToolkitTests.cs similarity index 64% rename from Cql/CoreTests/RuntimeApiTests.cs rename to Cql/CoreTests/FluentInvocationToolkitTests.cs index acff845f5..7eae5b197 100644 --- a/Cql/CoreTests/RuntimeApiTests.cs +++ b/Cql/CoreTests/FluentInvocationToolkitTests.cs @@ -1,8 +1,10 @@ #nullable enable using CoreTests.Tuples; using CqlSdkPrototype.Infrastructure; -using CqlSdkPrototype.Runtime; -using CqlSdkPrototype.Runtime.Extensions; +using CqlSdkPrototype.Invocation; +using CqlSdkPrototype.Invocation.Extensions; +using CqlSdkPrototype.Invocation.Fluent; +using CqlSdkPrototype.Invocation.Fluent.Extensions; using Hl7.Cql.Abstractions.Infrastructure; using Hl7.Cql.CodeGeneration.NET; using Hl7.Cql.Fhir; @@ -10,7 +12,7 @@ namespace CoreTests; [TestClass] -public class RuntimeApiTests +public class FluentInvocationToolkitTests { /// [TestMethod] @@ -22,14 +24,14 @@ public void TestRuntimeScopeAgainstLibraryDefinitionResults() .Select(dir => Path.GetFullPath(Path.Combine(dir.FullName, "Dlls", "CqlNestedTupleTest-1.0.0.dll"))) .First(File.Exists); var ctx = FhirCqlContext.ForBundle(); - using var invocationScope = new RuntimeApi() - .AddAssemblies([AssemblyData.Default.LoadFromFiles(new FileInfo(filePath))]) - .CreateRuntimeScope(); + using var librarySetInvoker = new FluentInvocationToolkit() + .AddAssemblyBinaries(AssemblyBinary.Default.LoadFromFile(new FileInfo(filePath))) + .ToLibrarySetInvoker(); // Act - var result = invocationScope + var result = librarySetInvoker .EnumerateLibraryDefinitionsResults(ctx, CqlVersionedLibraryIdentifier.Parse("CqlNestedTupleTest-1.0.0")) - .Select(t => (t.definition, t.getResult())) + .Select(t => (definition: t.definitionInvoker.DefinitionName, t.getResult())) .ToDictionary(); // Assert diff --git a/Cql/CoreTests/LibrarySetExpressionBuilderTests.cs b/Cql/CoreTests/LibrarySetExpressionBuilderTests.cs index 7c8c3fd84..aec2a9028 100644 --- a/Cql/CoreTests/LibrarySetExpressionBuilderTests.cs +++ b/Cql/CoreTests/LibrarySetExpressionBuilderTests.cs @@ -1,4 +1,4 @@ -using CqlSdkPrototype.Elm; +using CqlSdkPrototype.Elm.Internal; using Hl7.Cql.Abstractions; using Hl7.Cql.Compiler; using Hl7.Cql.Primitives; @@ -16,7 +16,7 @@ public class LibrarySetExpressionBuilderTests [TestMethod] public void LoadLibraryAndDependencies_CrossLibraryCodeSystems() { - var serviceProvider = ElmApiState.AddCqlCompilerServices(new ServiceCollection().AddDebugLogging()).BuildServiceProvider(validateScopes: true); + var serviceProvider = ElmToAssemblyProcessorServices.AddCqlCompilerServices(new ServiceCollection().AddDebugLogging()).BuildServiceProvider(validateScopes: true); using var servicesScope = serviceProvider.CreateScope(); LibrarySet librarySet = new(); librarySet.LoadLibraryAndDependencies(LibrarySetsDirs.Cms.ElmDir, "CumulativeMedicationDuration"); diff --git a/Cql/CoreTests/PrimitiveTests.cs b/Cql/CoreTests/PrimitiveTests.cs index 4b6abaca8..f38bbbfc2 100644 --- a/Cql/CoreTests/PrimitiveTests.cs +++ b/Cql/CoreTests/PrimitiveTests.cs @@ -5,14 +5,14 @@ using Hl7.Cql.Operators; using Hl7.Cql.Primitives; using Hl7.Cql.Runtime; -using CqlSdkPrototype.Elm; +using CqlSdkPrototype.Elm.Fluent; using Hl7.Cql.Runtime.Hosting; namespace CoreTests { using DateTimePrecision = Hl7.Cql.Iso8601.DateTimePrecision; using Expression = System.Linq.Expressions.Expression; - + [TestClass] [TestCategory("UnitTest")] public class PrimitiveTests @@ -3408,9 +3408,9 @@ public void Aggregate_Query_Test() Assert.That.DoesNotThrow(() => { - new ElmApi(loggerFactory) + new FluentElmToolkit(loggerFactory) .AddElmLibraries(librarySet) - .Compile(); + .CompileElmToAssemblies(); }); } diff --git a/Cql/CoreTests/QueriesTest.cs b/Cql/CoreTests/QueriesTest.cs index b474c6a82..4bbe4ffda 100644 --- a/Cql/CoreTests/QueriesTest.cs +++ b/Cql/CoreTests/QueriesTest.cs @@ -3,9 +3,9 @@ using Hl7.Cql.Runtime; using Hl7.Cql.ValueSets; using Hl7.Fhir.Model; -using CqlSdkPrototype.Elm; using Hl7.Cql.Compiler; using Hl7.Cql.Runtime.Hosting; +using CqlSdkPrototype.Elm.Internal; namespace CoreTests { @@ -15,7 +15,7 @@ public class QueriesTest [ClassInitialize] public static void Initialize(TestContext context) { - using var serviceProvider = ElmApiState.AddCqlCompilerServices(new ServiceCollection().AddDebugLogging()).BuildServiceProvider(validateScopes: true); + using var serviceProvider = ElmToAssemblyProcessorServices.AddCqlCompilerServices(new ServiceCollection().AddDebugLogging()).BuildServiceProvider(validateScopes: true); using var servicesScope = serviceProvider.CreateScope(); var elm = new FileInfo(@"Input\ELM\Test\QueriesTest-1.0.0.json"); diff --git a/Cql/CoreTests/Tuples/CqlTupleTests.cs b/Cql/CoreTests/Tuples/CqlTupleTests.cs index 74b2a5656..d2ff7adb3 100644 --- a/Cql/CoreTests/Tuples/CqlTupleTests.cs +++ b/Cql/CoreTests/Tuples/CqlTupleTests.cs @@ -1,7 +1,9 @@ #nullable enable using CqlSdkPrototype.Infrastructure; -using CqlSdkPrototype.Runtime; -using CqlSdkPrototype.Runtime.Extensions; +using CqlSdkPrototype.Invocation; +using CqlSdkPrototype.Invocation.Extensions; +using CqlSdkPrototype.Invocation.Fluent; +using CqlSdkPrototype.Invocation.Fluent.Extensions; using Hl7.Cql.Abstractions.Infrastructure; using Hl7.Cql.CodeGeneration.NET; using Hl7.Cql.Fhir; @@ -100,7 +102,7 @@ public void ExpressionReturningNestedTuplesFromDirectLibraryInstance_ResultCanBe """, str); } - /// + /// [TestMethod] public void ExpressionReturningNestedTuplesFromAssemblyLoadedLibraryInstance_ResultCanBeSerialized() { @@ -109,14 +111,14 @@ public void ExpressionReturningNestedTuplesFromAssemblyLoadedLibraryInstance_Res .Select(dir => Path.GetFullPath(Path.Combine(dir.FullName, "Dlls", "CqlNestedTupleTest-1.0.0.dll"))) .First(File.Exists); var ctx = FhirCqlContext.ForBundle(); - using var invocationScope = new RuntimeApi() - .AddAssemblies([AssemblyData.Default.LoadFromFiles(new FileInfo(filePath))]) - .CreateRuntimeScope(); + using var librarySetInvoker = new FluentInvocationToolkit() + .AddAssemblyBinaries(AssemblyBinary.Default.LoadFromFile(new FileInfo(filePath))) + .ToLibrarySetInvoker(); // Act - var result = invocationScope + var result = librarySetInvoker .EnumerateLibraryDefinitionsResults(ctx, CqlVersionedLibraryIdentifier.Parse("CqlNestedTupleTest-1.0.0")) - .Select(t => (t.definition, t.getResult())) + .Select(t => (definition: t.definitionInvoker.DefinitionName, t.getResult())) .ToDictionary(); Assert.IsNotNull(result); result.TryGetValue("Result", out var obj); diff --git a/Cql/Cql.Abstractions/Infrastructure/EnumerableExtensions.cs b/Cql/Cql.Abstractions/Infrastructure/EnumerableExtensions.cs index a4b4f7cb0..6b148f516 100644 --- a/Cql/Cql.Abstractions/Infrastructure/EnumerableExtensions.cs +++ b/Cql/Cql.Abstractions/Infrastructure/EnumerableExtensions.cs @@ -106,4 +106,9 @@ public static bool TryPeek( value = stack.Peek(); return true; } + + public static IEnumerable EnumerateSingle(this T item) + { + yield return item; + } } \ No newline at end of file diff --git a/Cql/Cql.Compiler/Infrastructure/Graphs/Traversal.cs b/Cql/Cql.Compiler/Infrastructure/Graphs/Traversal.cs index ea18c7427..8a90dec71 100644 --- a/Cql/Cql.Compiler/Infrastructure/Graphs/Traversal.cs +++ b/Cql/Cql.Compiler/Infrastructure/Graphs/Traversal.cs @@ -6,6 +6,8 @@ * available at https://raw.githubusercontent.com/FirelyTeam/firely-cql-sdk/main/LICENSE */ +using Hl7.Cql.Abstractions.Infrastructure; + namespace Hl7.Cql.Compiler.Infrastructure.Graphs; internal static class Traversal @@ -56,7 +58,7 @@ public static IEnumerable TopologicalSort( case 0: return []; case 1: - return EnumerateSingle(unvisited.First()); + return unvisited.First().EnumerateSingle(); } HashSet visited = []; @@ -88,9 +90,4 @@ public static IEnumerable TopologicalSort( return results; } - - private static IEnumerable EnumerateSingle(T first) - { - yield return first; - } } \ No newline at end of file diff --git a/Cql/Cql.CqlToElm/CqlToElmConverter.cs b/Cql/Cql.CqlToElm/CqlToElmConverter.cs index 8dad7ee9f..dcc7d206f 100644 --- a/Cql/Cql.CqlToElm/CqlToElmConverter.cs +++ b/Cql/Cql.CqlToElm/CqlToElmConverter.cs @@ -23,11 +23,12 @@ public CqlToElmConverter(IServiceProvider services, /// /// CQL to Elm IServiceProvider /// - public IServiceProvider Services { get; } + private IServiceProvider Services { get; } + /// /// CQL to Elm Logger /// - public ILogger Logger { get; } + private ILogger Logger { get; } /// /// Converts the CQL contained in to an ELM . @@ -70,17 +71,9 @@ internal LibraryBuilder GetBuilder(LibraryVisitor libraryVisitor, string cql) internal LibraryBuilder GetBuilder(LibraryVisitor libraryVisitor, TextReader cqlReader) { - try - { - var libraryContext = ParseLibrary(cqlReader); - var libraryBuilder = libraryVisitor.Visit(libraryContext); - return libraryBuilder; - } - catch (Exception e) - { - Logger.LogCritical(e, "Exception while converting CQL to ELM."); - throw; - } + var libraryContext = ParseLibrary(cqlReader); + var libraryBuilder = libraryVisitor.Visit(libraryContext); + return libraryBuilder; } internal static LibraryVisitor GetLibraryVisitorScoped(IServiceScope scope) diff --git a/Cql/Cql.CqlToElm/DependencyInjection/CqlToElmServiceProviderExtensions.cs b/Cql/Cql.CqlToElm/DependencyInjection/CqlToElmServiceProviderExtensions.cs deleted file mode 100644 index 98180bc0f..000000000 --- a/Cql/Cql.CqlToElm/DependencyInjection/CqlToElmServiceProviderExtensions.cs +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2024, NCQA and contributors - * See the file CONTRIBUTORS for details. - * - * This file is licensed under the BSD 3-Clause license - * available at https://raw.githubusercontent.com/FirelyTeam/firely-cql-sdk/main/LICENSE - */ - -using Hl7.Cql.CqlToElm; -using Hl7.Cql.CqlToElm.Builtin; -using Hl7.Cql.CqlToElm.LibraryProviders; - -// ReSharper disable once CheckNamespace -#pragma warning disable IDE0130 // Namespace does not match folder structure -namespace Microsoft.Extensions.DependencyInjection; - -internal static class CqlToElmServiceProviderExtensions -{ - public static CqlToElmConverter GetCqlToElmConverter(this IServiceProvider sp) => sp.GetRequiredService(); - - public static CoercionProvider GetCoercionProvider(this IServiceProvider sp) => sp.GetRequiredService(); - - public static ElmFactory GetElmFactory(this IServiceProvider sp) => sp.GetRequiredService(); - - public static SystemLibrary GetSystemLibrary(this IServiceProvider sp) => sp.GetRequiredService(); - - public static StreamInspector GetStreamInspector(this IServiceProvider sp) => sp.GetRequiredService(); - - public static InvocationBuilder GetInvocationBuilder(this IServiceProvider sp) => sp.GetRequiredService(); - - public static LocalIdentifierProvider GetLocalIdentifierProviderTransient(this IServiceProvider sp) => sp.GetRequiredService(); - - public static MessageProvider GetMessageProvider(this IServiceProvider sp) => sp.GetRequiredService(); - - public static IModelProvider GetModelProvider(this IServiceProvider sp) => sp.GetRequiredService(); -} \ No newline at end of file diff --git a/Cql/Cql.CqlToElm/PublicAPI.Unshipped.txt b/Cql/Cql.CqlToElm/PublicAPI.Unshipped.txt index c889221a7..6d4dc9fb1 100644 --- a/Cql/Cql.CqlToElm/PublicAPI.Unshipped.txt +++ b/Cql/Cql.CqlToElm/PublicAPI.Unshipped.txt @@ -8,8 +8,6 @@ Hl7.Cql.CqlToElm.CqlToElmConverter.ConvertLibrary(string! cql) -> Hl7.Cql.Elm.Li Hl7.Cql.CqlToElm.CqlToElmConverter.ConvertLibrary(System.IO.Stream! cqlLibrary) -> Hl7.Cql.Elm.Library! Hl7.Cql.CqlToElm.CqlToElmConverter.ConvertLibrary(System.IO.TextReader! cqlLibrary) -> Hl7.Cql.Elm.Library! Hl7.Cql.CqlToElm.CqlToElmConverter.CqlToElmConverter(System.IServiceProvider! services, Microsoft.Extensions.Logging.ILogger! logger) -> void -Hl7.Cql.CqlToElm.CqlToElmConverter.Logger.get -> Microsoft.Extensions.Logging.ILogger! -Hl7.Cql.CqlToElm.CqlToElmConverter.Services.get -> System.IServiceProvider! Hl7.Cql.CqlToElm.CqlToElmOptions Hl7.Cql.CqlToElm.CqlToElmOptions.AllowNullIntervals.get -> bool? Hl7.Cql.CqlToElm.CqlToElmOptions.AllowNullIntervals.set -> void diff --git a/Cql/Cql.Packaging/ResourcePackager.cs b/Cql/Cql.Packaging/ResourcePackager.cs index 29fc5ebe0..bc6280c7f 100644 --- a/Cql/Cql.Packaging/ResourcePackager.cs +++ b/Cql/Cql.Packaging/ResourcePackager.cs @@ -14,6 +14,7 @@ using Hl7.Cql.Primitives; using Hl7.Fhir.Model; using Hl7.Fhir.Utility; +using DateTime = System.DateTime; namespace Hl7.Cql.Packaging; @@ -30,14 +31,14 @@ namespace Hl7.Cql.Packaging; internal class ResourcePackager( TypeResolver typeResolver) { - // private readonly FhirResourcePostProcessor? _fhirResourcePostProcessor = fhirResourcePostProcessor; + private readonly CqlTypeToFhirTypeMapper _cqlTypeToFhirTypeMapper = new(typeResolver); public IReadOnlyCollection PackageResources( DirectoryInfo elmDirectory, DirectoryInfo cqlDirectory, string? resourceCanonicalRootUrl, LibrarySet elmLibrarySet, - IReadOnlyDictionary assembliesByLibraryName) + IReadOnlyDictionary assembliesByLibraryName) { var resources = new List(); var librariesByVersionedIdentifier = new Dictionary(); @@ -47,8 +48,6 @@ void OnResourceCreated(FhirResource resource) resources!.Add(resource); } - var typeCrosswalk = new CqlTypeToFhirTypeMapper(typeResolver); - foreach (var (name, asmData) in assembliesByLibraryName) { var library = elmLibrarySet.GetLibrary(name)!; @@ -76,7 +75,7 @@ void OnResourceCreated(FhirResource resource) if (library.GetVersionedIdentifier() is null) throw new InvalidOperationException("Library VersionedIdentifier should not be null."); - var fhirLibrary = LibraryPackager.CreateLibraryResource(elmFile, cqlFile, resourceCanonicalRootUrl, asmData, typeCrosswalk, library); + var fhirLibrary = LibraryPackager.CreateLibraryResource(elmFile, cqlFile, resourceCanonicalRootUrl, asmData, _cqlTypeToFhirTypeMapper, library); librariesByVersionedIdentifier.Add(library.GetVersionedIdentifier()!, fhirLibrary); // Analyze datarequirements and add to the FHIR Library resource. @@ -264,14 +263,14 @@ from p in populations } } -file static class LibraryPackager +internal static class LibraryPackager { public static FhirLibrary CreateLibraryResource( FileInfo elmFile, FileInfo? cqlFile, string? resourceCanonicalRootUrl, - AssemblyDataWithSourceCode assemblyDataWithSourceCode, - CqlTypeToFhirTypeMapper typeCrosswalk, + AssemblyBinaryWithSourceCode assemblyBinaryWithSourceCode, + CqlTypeToFhirTypeMapper cqlTypeToFhirTypeMapper, ElmLibrary? elmLibrary = null) { if (!elmFile.Exists) @@ -284,8 +283,27 @@ public static FhirLibrary CreateLibraryResource( throw new ArgumentException($"File at {elmFile.FullName} is not valid ELM"); } - var fhirLibrary = CreateFhirLibrary(elmLibrary, elmFile, resourceCanonicalRootUrl); - AddElmAttachment(elmLibrary, elmFile, fhirLibrary); + var elmFileLastWriteTimeUtc = elmFile.LastWriteTimeUtc; + var elmBytes = File.ReadAllBytes(elmFile.FullName); + byte[]? cqlBytes = null; + if (cqlFile!.Exists) + cqlBytes = File.ReadAllBytes(cqlFile.FullName); + + return CreateLibraryResource(cqlTypeToFhirTypeMapper, elmLibrary, elmBytes, cqlBytes, assemblyBinaryWithSourceCode.AssemblyBytes, assemblyBinaryWithSourceCode.SourceCode, resourceCanonicalRootUrl, elmFileLastWriteTimeUtc); + } + + public static FhirLibrary CreateLibraryResource( + CqlTypeToFhirTypeMapper typeCrosswalk, + ElmLibrary elmLibrary, + byte[] elmBytes, + byte[]? cqlBytes, + byte[]? assemblyBytes, + IEnumerable>? cSharpSourceCodeById, + string? resourceCanonicalRootUrl, + DateTime? elmFileLastWriteTimeUtc) + { + var fhirLibrary = CreateFhirLibrary(elmLibrary, resourceCanonicalRootUrl, elmFileLastWriteTimeUtc ?? DateTime.Now); + AddElmAttachment(elmLibrary, fhirLibrary, elmBytes); var parameters = new List(); AddInParameters(elmLibrary, parameters, typeCrosswalk); AddOutParameters(elmLibrary, parameters, typeCrosswalk); @@ -295,24 +313,27 @@ public static FhirLibrary CreateLibraryResource( var fhirParameters = CreateFhirParameters(elmLibrary); if (fhirParameters.Any()) - AddCQLOptions(fhirLibrary, fhirParameters); + AddCqlOptions(fhirLibrary, fhirParameters); - if (cqlFile!.Exists) - AddCqlAttachment(elmLibrary, fhirLibrary, cqlFile); + if (cqlBytes != null) + AddCqlAttachment(elmLibrary, fhirLibrary, cqlBytes); + + if (assemblyBytes != null) + AddDllAttachment(elmLibrary, fhirLibrary, assemblyBytes); - AddDllAttachment(elmLibrary, fhirLibrary, assemblyDataWithSourceCode); - foreach (var kvp in assemblyDataWithSourceCode.SourceCode!) - AddCSharpAttachment(fhirLibrary, kvp); + if (cSharpSourceCodeById != null) + foreach (var kvp in cSharpSourceCodeById) + AddCSharpAttachment(fhirLibrary, kvp); return fhirLibrary; } private static void AddElmAttachment( ElmLibrary elmLibrary, - FileInfo elmFile, - FhirLibrary fhirLibrary) + FhirLibrary fhirLibrary, + byte[] elmBytes) { - var bytes = File.ReadAllBytes(elmFile.FullName); + var bytes = elmBytes; var attachment = new Attachment { ElementId = $"{elmLibrary.GetVersionedIdentifier()}+elm", @@ -324,8 +345,8 @@ private static void AddElmAttachment( private static FhirLibrary CreateFhirLibrary( ElmLibrary elmLibrary, - FileInfo elmFile, - string? resourceCanonicalRootUrl) + string? resourceCanonicalRootUrl, + DateTime date) { var fhirLibrary = new FhirLibrary(); fhirLibrary.Type = LogicLibraryCodeableConcept; @@ -333,7 +354,7 @@ private static FhirLibrary CreateFhirLibrary( fhirLibrary.Version = elmLibrary.identifier?.version!; fhirLibrary.Name = elmLibrary.identifier?.id!; fhirLibrary.Status = PublicationStatus.Active; - fhirLibrary.Date = new DateTimeIso8601(elmFile.LastWriteTimeUtc, DateTimePrecision.Millisecond).ToString(); + fhirLibrary.Date = new DateTimeIso8601(date, DateTimePrecision.Millisecond).ToString(); fhirLibrary.Url = fhirLibrary.CanonicalUri(resourceCanonicalRootUrl); return fhirLibrary; } @@ -398,10 +419,8 @@ private static void AddInParameters( private static void AddCqlAttachment( ElmLibrary? elmLibrary, FhirLibrary fhirLibrary, - FileInfo cqlFile) + byte[] cqlBytes) { - var cqlBytes = File.ReadAllBytes(cqlFile.FullName); - var attachment = new Attachment { ElementId = $"{elmLibrary!.GetVersionedIdentifier()}+cql", @@ -411,7 +430,7 @@ private static void AddCqlAttachment( fhirLibrary.Content.Add(attachment); } - private static void AddCQLOptions( + private static void AddCqlOptions( FhirLibrary fhirLibrary, IReadOnlyList fhirParameters) { @@ -453,9 +472,8 @@ private static void AddCSharpAttachment(FhirLibrary library, KeyValuePair? filePredicate = null) + { + var files = directory.EnumerateFiles("*.cql", options ?? InternalConstants.DefaultEnumerationOptions); + if (filePredicate is not null) files = files.Where(filePredicate); + return cqlToolkit.AddCqlLibraryFiles(files); + } + + public static FluentCqlToolkit AddCqlLibraryFiles( + this FluentCqlToolkit cqlToolkit, + IEnumerable files) + { + var logger = cqlToolkit.CreateLogger(); + var cqlLibraries = files + .Select(f => + { + logger.LogInformation("Loading library from file: {file}", f); + var cqlContent = File.ReadAllText(f.FullName); + var cqlLibrary = CqlLibraryString.Parse(cqlContent); + return cqlLibrary; + }); // Log errors + + return cqlToolkit.AddCqlLibraries(cqlLibraries); + } +} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql/Extensions/CqlApiExtensions.Saving.cs b/Cql/CqlSdkPrototype/Cql.Fluent/Extensions/FluentCqlToolkitExtensions.Saving.cs similarity index 51% rename from Cql/CqlSdkPrototype/Cql/Extensions/CqlApiExtensions.Saving.cs rename to Cql/CqlSdkPrototype/Cql.Fluent/Extensions/FluentCqlToolkitExtensions.Saving.cs index 61e2806d5..affa42ff7 100644 --- a/Cql/CqlSdkPrototype/Cql/Extensions/CqlApiExtensions.Saving.cs +++ b/Cql/CqlSdkPrototype/Cql.Fluent/Extensions/FluentCqlToolkitExtensions.Saving.cs @@ -1,21 +1,18 @@ -using CqlSdkPrototype.Cql.Extensibility; +namespace CqlSdkPrototype.Cql.Fluent.Extensions; -namespace CqlSdkPrototype.Cql.Extensions; - -public static partial class CqlApiExtensions +public static partial class FluentCqlToolkitExtensions { - public static TCqlApi SaveElmFileToDirectory( - this TCqlApi cqlApi, + public static FluentCqlToolkit SaveElmFilesToDirectory( + this FluentCqlToolkit cqlToolkit, DirectoryInfo directory, bool writeIndented = true) - where TCqlApi : ICqlApiExtendable { if (!directory.Exists) directory.Create(); - var logger = cqlApi.LoggerFactory.CreateLogger(typeof(CqlApiExtensions)); + var logger = cqlToolkit.CreateLogger(); - foreach (var (libraryName, (_, elmLibrary)) in cqlApi.Entries) + foreach (var (libraryName, (_, elmLibrary)) in cqlToolkit.CqlToElmTranslations) { if (elmLibrary == null) continue; @@ -25,6 +22,6 @@ public static TCqlApi SaveElmFileToDirectory( logger.LogInformation("Saved ELM to file: {file}", fileName); } - return cqlApi; + return cqlToolkit; } } \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql.Fluent/Extensions/FluentCqlToolkitExtensions.cs b/Cql/CqlSdkPrototype/Cql.Fluent/Extensions/FluentCqlToolkitExtensions.cs new file mode 100644 index 000000000..3cca58a9f --- /dev/null +++ b/Cql/CqlSdkPrototype/Cql.Fluent/Extensions/FluentCqlToolkitExtensions.cs @@ -0,0 +1,17 @@ +using Hl7.Cql.Abstractions.Exceptions; + +namespace CqlSdkPrototype.Cql.Fluent.Extensions; + +public static partial class FluentCqlToolkitExtensions +{ + private static ILogger CreateLogger(this FluentCqlToolkit cqlToolkit) => + cqlToolkit.LoggerFactory.CreateLogger(typeof(FluentCqlToolkitExtensions)); + + public static FluentCqlToolkit ConfigIgnoreExceptions(this FluentCqlToolkit cqlToolkit, bool stopAfterFirstException = false) => + cqlToolkit.Reconfigure(o => o with + { + ProcessBatchItemExceptionHandling = stopAfterFirstException + ? ProcessBatchItemExceptionHandling.IgnoreExceptionAndBreak + : ProcessBatchItemExceptionHandling.IgnoreExceptionAndContinue + }); +} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql.Fluent/FluentCqlToolkit.cs b/Cql/CqlSdkPrototype/Cql.Fluent/FluentCqlToolkit.cs new file mode 100644 index 000000000..ab62900c1 --- /dev/null +++ b/Cql/CqlSdkPrototype/Cql.Fluent/FluentCqlToolkit.cs @@ -0,0 +1,72 @@ +using CqlSdkPrototype.Infrastructure; + +namespace CqlSdkPrototype.Cql.Fluent; + +/// +/// Provides a fluent interface for working with CQL to ELM translations. +/// +public sealed class FluentCqlToolkit(CqlToElmTranslator cqlToElmTranslator) +{ + /// + /// Initializes a new instance of the class. + /// + /// The logger factory to use for logging. + /// The configuration settings for the translator. + public FluentCqlToolkit( + ILoggerFactory? loggerFactory = null, + CqlToElmTranslatorConfig? config = null) : this(new CqlToElmTranslator(loggerFactory, config)) + { + } + + /// + /// Gets the service provider used by tests. + /// + internal ServiceProvider ServiceProvider => cqlToElmTranslator.ServiceProvider; + + /// + /// Gets the logger factory used by extensions. + /// + public ILoggerFactory LoggerFactory => cqlToElmTranslator.LoggerFactory; + + /// + /// Gets the configuration settings for the translator. + /// + public CqlToElmTranslatorConfig Config => cqlToElmTranslator.Config; + + /// + /// Gets the dictionary of CQL to ELM translations. + /// + public CqlToElmTranslationReadOnlyDictionary CqlToElmTranslations => cqlToElmTranslator.CqlToElmTranslations; + + /// + /// Reconfigures the translator with new configuration settings. + /// + /// A function that takes the current configuration and returns a new configuration. + /// The current instance of . + public FluentCqlToolkit Reconfigure(Func configure) + { + cqlToElmTranslator.Reconfigure(configure(Config)); + return this; + } + + /// + /// Adds CQL libraries to the translator. + /// + /// The CQL libraries to add. + /// The current instance of . + public FluentCqlToolkit AddCqlLibraries(IEnumerable libraries) + { + cqlToElmTranslator.AddCqlLibraries(libraries); + return this; + } + + /// + /// Translates the CQL libraries to ELM libraries. + /// + /// The current instance of . + public FluentCqlToolkit TranslateCqlToElm() + { + cqlToElmTranslator.TranslateCqlToElm(); + return this; + } +} diff --git a/Cql/CqlSdkPrototype/Cql/CqlApi.cs b/Cql/CqlSdkPrototype/Cql/CqlApi.cs deleted file mode 100644 index 6dcb73518..000000000 --- a/Cql/CqlSdkPrototype/Cql/CqlApi.cs +++ /dev/null @@ -1,143 +0,0 @@ -using CqlSdkPrototype.Cql.Extensibility; -using CqlSdkPrototype.Cql.Internal; -using CqlSdkPrototype.Infrastructure; -using CqlSdkPrototype.Internal; -using Hl7.Cql.CqlToElm; -using Hl7.Cql.Runtime; - -namespace CqlSdkPrototype.Cql; - -public class CqlApi : - ICqlApiExtendable, - ICqlApiInternal -{ - public CqlApi( - ILoggerFactory? loggerFactory = null, - CqlApiOptions? options = null) - { - options ??= CqlApiOptions.Default; - var entries = CqlApiStateEntryDictionary.Empty.WithComparers(CqlVersionedLibraryIdentifier.IdentifierOnlyEqualityComparer); - var entriesBuilder = entries.ToBuilder(); - var libraryProvider = new EntriesBuilderLibraryProvider(entriesBuilder); - _entries = entries; - _services = CqlApiServices.Create(loggerFactory ?? NullLoggerFactory.Instance, options, libraryProvider); - _options = options; - } - - #region State - - private CqlApiServices _services; - private CqlApiStateEntryDictionary _entries; - private CqlApiOptions _options; - - private CqlApi WithEntries( - CqlApiStateEntryDictionary entries) - { - _entries = entries; - _services.LibraryProvider.EntriesBuilder = entries.ToBuilder(); - return this; - } - - public CqlApi WithOptions( - Func replaceOptions) - { - var libraryProvider = _services.LibraryProvider; - _services.ServiceProvider.Dispose(); - _options = replaceOptions(_options); - _services = CqlApiServices.Create(_services.LoggerFactory, _options, libraryProvider); - return this; - } - - ILoggerFactory ICqlApiExtendable.LoggerFactory => _services.LoggerFactory; - CqlApiOptions ICqlApiExtendable.Options => _options; - IReadOnlyDictionary ICqlApiExtendable.Entries => _entries; - CqlApiServices ICqlApiInternal.Services => _services; - - #endregion - - #region Input (CQL Library Strings) - - public CqlApi AddCqlLibraries(IEnumerable cqlLibraries) - { - var logger = _services.Logger; - var entriesBuilder = _services.LibraryProvider.EntriesBuilder; - var cqlToElmConverter = _services.CqlToElmConverter; - using var scope = _services.ServiceProvider.CreateScope()!; - var hasChanged = false; - foreach (var cqlLibrary in cqlLibraries) - { - var versionedIdentifier = cqlLibrary.VersionedLibraryIdentifier; - - if (entriesBuilder.ContainsKey(versionedIdentifier)) - { - logger.LogInformation("Skipping adding previous cql to translation: {versionedIdentifier}", versionedIdentifier); - continue; - } - - var libraryVisitor = CqlToElmConverter.GetLibraryVisitorScoped(scope); - var libraryBuilder = cqlToElmConverter.GetBuilder(libraryVisitor, cqlLibrary.Cql); - var entry = new CqlApiStateEntry(cqlLibrary) { ElmLibraryBuilder = libraryBuilder }; - entriesBuilder.Add(versionedIdentifier, entry); - logger.LogInformation("Adding cql library to translation: {versionedIdentifier}", versionedIdentifier); - hasChanged = true; - } - - return hasChanged - ? WithEntries(entries: entriesBuilder.ToImmutable()) - : this; - } - - #endregion - - #region Processing (CQL-to-ELM) - - public CqlApi Translate() - { - CqlApiStateEntryDictionary.Builder entriesBuilder = _services.LibraryProvider.EntriesBuilder; - var logger = _services.Logger; - bool atFirst = true; - - IEnumerable<(CqlVersionedLibraryIdentifier versionedIdentifier, CqlApiStateEntry cqlTranslationEntry)> GetLibrariesForProcessing() - { - foreach (var (versionedIdentifier, cqlTranslationEntry) in - _entries.Where(kv => kv.Value.ElmLibrary is null)) - { - if (atFirst) - { - atFirst = false; - logger.LogInformation("Translating CQL into ELM"); - } - - logger.LogInformation("Translating CQL: {id}", versionedIdentifier); - yield return (versionedIdentifier, cqlTranslationEntry); - } - } - - LogExceptionMessageAction log = logger.GetLogExceptionMessageAction(_options.ProcessBatchItemExceptionHandling); - - int changedCount = - GetLibrariesForProcessing() - .TryProcessEach(t => ProcessLibrary(t.versionedIdentifier, t.cqlTranslationEntry)) - .WithEachException(outcome => - { - var libraryName = outcome.Input.versionedIdentifier; - log(outcome.Exception, "Error translating CQL library '{libraryName}' to ELM.", libraryName); - }) - .HandleExceptions(_options.ProcessBatchItemExceptionHandling) - .Count() // We must enumerate all - ; - - if (changedCount <= 0) - return this; - - return WithEntries(entries: entriesBuilder.ToImmutable()); - - void ProcessLibrary(CqlVersionedLibraryIdentifier versionedIdentifier, CqlApiStateEntry cqlTranslationEntry) - { - var library = cqlTranslationEntry.ElmLibraryBuilder!.Build(); - entriesBuilder[versionedIdentifier] = cqlTranslationEntry with { ElmLibrary = library }; - } - } - - #endregion -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql/CqlModel.cs b/Cql/CqlSdkPrototype/Cql/CqlModel.cs index 73dd7789b..1b80dabf6 100644 --- a/Cql/CqlSdkPrototype/Cql/CqlModel.cs +++ b/Cql/CqlSdkPrototype/Cql/CqlModel.cs @@ -1,7 +1,19 @@ -namespace CqlSdkPrototype.Cql; +using Hl7.Cql.Model; +namespace CqlSdkPrototype.Cql; + +/// +/// Represents the model of CQL to use. +/// public enum CqlModel { + /// + /// Represents the ELM R1 model which maps to + /// ElmR1 = 1, + + /// + /// Represents the FHIR 4.0.1 model which maps to + /// Fhir401 = 2, } \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql/CqlToElmTranslation.cs b/Cql/CqlSdkPrototype/Cql/CqlToElmTranslation.cs new file mode 100644 index 000000000..fbfe9cd16 --- /dev/null +++ b/Cql/CqlSdkPrototype/Cql/CqlToElmTranslation.cs @@ -0,0 +1,20 @@ +using CqlSdkPrototype.Infrastructure; +using Hl7.Cql.CqlToElm; +using Hl7.Cql.Elm; + +namespace CqlSdkPrototype.Cql; + +/// +/// Represents a translation from a CQL library to an ELM library. +/// +/// The input CQL library string. +/// The output ELM library. +public readonly record struct CqlToElmTranslation( + CqlLibraryString CqlLibraryString, + Library? ElmLibrary = null) { + + /// + /// The builder for the ELM library. This is set during . + /// + internal LibraryBuilder? ElmLibraryBuilder { get; init; } +} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql/CqlToElmTranslator.cs b/Cql/CqlSdkPrototype/Cql/CqlToElmTranslator.cs new file mode 100644 index 000000000..145277f7c --- /dev/null +++ b/Cql/CqlSdkPrototype/Cql/CqlToElmTranslator.cs @@ -0,0 +1,191 @@ +using CqlSdkPrototype.Cql.Fluent; +using CqlSdkPrototype.Cql.Internal; +using CqlSdkPrototype.Infrastructure; +using CqlSdkPrototype.Internal; +using Hl7.Cql.CqlToElm; +using Hl7.Cql.Runtime; + +namespace CqlSdkPrototype.Cql; + +/// +/// Translates CQL libraries to ELM libraries. +/// +public sealed class CqlToElmTranslator +{ + /// + /// Initializes a new instance of the class. + /// + /// The logger factory to use for logging. + /// The configuration settings for the translator. + public CqlToElmTranslator( + ILoggerFactory? loggerFactory = null, + CqlToElmTranslatorConfig? config = null) + { + config ??= CqlToElmTranslatorConfig.Default; + loggerFactory ??= NullLoggerFactory.Instance; + LoggerFactory = loggerFactory; + _cqlToElmTranslations = CqlToElmTranslationDictionary.Empty; + Config = config; + _services = CqlToElmTranslatorServices.Create(loggerFactory, config, _cqlToElmTranslations); + } + + private CqlToElmTranslationDictionary _cqlToElmTranslations; + private CqlToElmTranslatorServices _services; + + /// + /// Gets the logger factory used by extensions via . + /// + internal ILoggerFactory LoggerFactory { get; } + + /// + /// Gets the service provider used by tests via . + /// + internal ServiceProvider ServiceProvider => _services.ServiceProvider; + + /// + /// Gets the configuration settings for the translator. + /// + public CqlToElmTranslatorConfig Config { get; private set; } + + /// + /// Gets the dictionary of CQL to ELM translations. + /// + public CqlToElmTranslationReadOnlyDictionary CqlToElmTranslations => _cqlToElmTranslations; + + /// + /// Sets the CQL to ELM conversions. + /// + /// The dictionary of translations to set. + private void SetCqlToElmTranslations( + CqlToElmTranslationDictionary translations) + { + _cqlToElmTranslations = translations; + _services.LibraryBuilderProvider.TranslationsBuilder = translations.ToBuilder(); + } + + /// + /// Reconfigures the translator with new configuration settings. + /// + /// The new configuration settings. + public void Reconfigure( + CqlToElmTranslatorConfig config) + { + if (Config == config) + return; + + _services.ServiceProvider.Dispose(); + Config = config; + _services = CqlToElmTranslatorServices.Create(_services.LoggerFactory, config, _cqlToElmTranslations); + } + + /// + /// Adds CQL libraries to the translator. + /// + /// The CQL libraries to add. + public void AddCqlLibraries(IEnumerable cqlLibraries) + { + var logger = _services.Logger; + var entriesBuilder = _services.LibraryBuilderProvider.TranslationsBuilder; + LogExceptionMessageAction log = logger.GetLogExceptionMessageAction(Config.ProcessBatchItemExceptionHandling); + + int addedCount = + BuildTranslations(cqlLibraries, entriesBuilder) + .TryProcessEach(t => (t.cqlLibraryString, cqlToElmTranslation: t.cqlToElmTranslationFn())) + .WithEachException(outcome => + { + var libraryName = outcome.Input.cqlLibraryString.VersionedLibraryIdentifier; + log(outcome.Exception, "Error parsing CQL library '{libraryName}' to ELM.", libraryName); + }) + .HandleExceptions(Config.ProcessBatchItemExceptionHandling) + .Count() // We must enumerate all + ; + + if (addedCount > 0) + SetCqlToElmTranslations(translations: entriesBuilder.ToImmutable()); + } + + /// + /// Builds the translations for the given CQL libraries. + /// + /// The CQL libraries to translate. + /// The builder for the translation entries. + /// A collection of CQL library strings and their corresponding translation functions. + private IEnumerable<(CqlLibraryString cqlLibraryString, Func cqlToElmTranslationFn)> BuildTranslations( + IEnumerable cqlLibraries, + CqlToElmTranslationDictionary.Builder entriesBuilder) + { + var logger = _services.Logger; + var cqlToElmConverter = _services.CqlToElmConverter; + using var scope = _services.ServiceProvider.CreateScope()!; + foreach (var cqlLibrary in cqlLibraries) + { + var versionedIdentifier = cqlLibrary.VersionedLibraryIdentifier; + + if (entriesBuilder.ContainsKey(versionedIdentifier)) + { + logger.LogInformation("Skipping adding previous cql to translation: {versionedIdentifier}", versionedIdentifier); + continue; + } + + yield return (cqlLibrary, + () => + { + var libraryVisitor = CqlToElmConverter.GetLibraryVisitorScoped(scope); + var libraryBuilder = cqlToElmConverter.GetBuilder(libraryVisitor, cqlLibrary.Cql); + var translation = new CqlToElmTranslation(cqlLibrary) { ElmLibraryBuilder = libraryBuilder }; + entriesBuilder.Add(versionedIdentifier, translation); + return translation; + } + ); + } + } + + /// + /// Translates the CQL libraries to ELM libraries. + /// + public void TranslateCqlToElm() + { + CqlToElmTranslationDictionary.Builder processItemsBuilder = _services.LibraryBuilderProvider.TranslationsBuilder; + var logger = _services.Logger; + bool atFirst = true; + + IEnumerable<(CqlVersionedLibraryIdentifier versionedIdentifier, CqlToElmTranslation cqlTranslationEntry)> GetLibrariesForProcessing() + { + foreach (var (versionedIdentifier, cqlTranslationEntry) in + _cqlToElmTranslations.Where(kv => kv.Value.ElmLibrary is null)) + { + if (atFirst) + { + atFirst = false; + logger.LogInformation("Translating CQL into ELM"); + } + + logger.LogInformation("Translating CQL: {id}", versionedIdentifier); + yield return (versionedIdentifier, cqlTranslationEntry); + } + } + + LogExceptionMessageAction log = logger.GetLogExceptionMessageAction(Config.ProcessBatchItemExceptionHandling); + + int changedCount = + GetLibrariesForProcessing() + .TryProcessEach(t => ProcessLibrary(t.versionedIdentifier, t.cqlTranslationEntry)) + .WithEachException(outcome => + { + var libraryName = outcome.Input.versionedIdentifier; + log(outcome.Exception, "Error translating CQL library '{libraryName}' to ELM.", libraryName); + }) + .HandleExceptions(Config.ProcessBatchItemExceptionHandling) + .Count() // We must enumerate all + ; + + if (changedCount > 0) + SetCqlToElmTranslations(translations: processItemsBuilder.ToImmutable()); + + void ProcessLibrary(CqlVersionedLibraryIdentifier versionedIdentifier, CqlToElmTranslation cqlTranslationEntry) + { + var library = cqlTranslationEntry.ElmLibraryBuilder!.Build(); + processItemsBuilder[versionedIdentifier] = cqlTranslationEntry with { ElmLibrary = library }; + } + } +} diff --git a/Cql/CqlSdkPrototype/Cql/CqlApiOptions.cs b/Cql/CqlSdkPrototype/Cql/CqlToElmTranslatorConfig.cs similarity index 79% rename from Cql/CqlSdkPrototype/Cql/CqlApiOptions.cs rename to Cql/CqlSdkPrototype/Cql/CqlToElmTranslatorConfig.cs index cb2916187..2935bb48f 100644 --- a/Cql/CqlSdkPrototype/Cql/CqlApiOptions.cs +++ b/Cql/CqlSdkPrototype/Cql/CqlToElmTranslatorConfig.cs @@ -4,8 +4,10 @@ namespace CqlSdkPrototype.Cql; -public record CqlApiOptions -( +/// +/// The settings used to configure the CQL to ELM processor. +/// +public sealed record CqlToElmTranslatorConfig( ProcessBatchItemExceptionHandling ProcessBatchItemExceptionHandling = default, ImmutableHashSet? Models = null, ImmutableHashSet? ModelInfos = null, @@ -14,13 +16,18 @@ public record CqlApiOptions bool EnableListPromotion = false, bool EnableIntervalPromotion = false, bool EnableIntervalDemotion = false, - bool AllowNullInterval = false - ) + bool AllowNullIntervals = false) { - public static CqlApiOptions Default { get; } = new(); + public static CqlToElmTranslatorConfig Default { get; } = new(); + /// + /// The model information to use when translating CQL to ELM. + /// public ImmutableHashSet Models { get; init; } = Models ?? []; + /// + /// The model information to use when translating CQL to ELM. + /// public ImmutableHashSet ModelInfos { get; init; } = ModelInfos ?? []; /// @@ -30,7 +37,7 @@ public record CqlApiOptions /// The default value is . /// /// - public bool AllowNullIntervals { get; set; } = AllowNullInterval; + public bool AllowNullIntervals { get; init; } = AllowNullIntervals; /// /// When , point intervals will automatically be created as necessary from scalar values. @@ -68,7 +75,7 @@ public record CqlApiOptions /// This type of conversion will issue a warning and could fail at runtime. /// /// - public bool EnableListDemotion { get; set; } = EnableListDemotion; + public bool EnableListDemotion { get; init; } = EnableListDemotion; /// /// @@ -80,17 +87,14 @@ public record CqlApiOptions /// /// public AmbiguousTypeBehavior AmbiguousTypeBehavior { get; init; } = AmbiguousTypeBehavior; -} -internal static class CqlApiOptionsExtensions -{ - internal static void ApplyToCqlToElmOptions(this CqlApiOptions options, CqlToElmOptions opt) + internal void ApplyToCqlToElmOptions(CqlToElmOptions opt) { - opt.AmbiguousTypeBehavior = options.AmbiguousTypeBehavior; - opt.EnableListPromotion = options.EnableListPromotion; - opt.EnableListDemotion = options.EnableListDemotion; - opt.EnableIntervalPromotion = options.EnableIntervalPromotion; - opt.EnableIntervalDemotion = options.EnableIntervalDemotion; - opt.AllowNullIntervals = options.AllowNullIntervals; + opt.AmbiguousTypeBehavior = AmbiguousTypeBehavior; + opt.EnableListPromotion = EnableListPromotion; + opt.EnableListDemotion = EnableListDemotion; + opt.EnableIntervalPromotion = EnableIntervalPromotion; + opt.EnableIntervalDemotion = EnableIntervalDemotion; + opt.AllowNullIntervals = AllowNullIntervals; } } \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql/Extensibility/CqlApiExtendableExtensions.cs b/Cql/CqlSdkPrototype/Cql/Extensibility/CqlApiExtendableExtensions.cs deleted file mode 100644 index f7bef000e..000000000 --- a/Cql/CqlSdkPrototype/Cql/Extensibility/CqlApiExtendableExtensions.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace CqlSdkPrototype.Cql.Extensibility; - -public static class CqlApiExtendableExtensions -{ - public static ICqlApiExtendable AsExtendable(this CqlApi self) => self; -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql/Extensibility/CqlApiStateEntry.cs b/Cql/CqlSdkPrototype/Cql/Extensibility/CqlApiStateEntry.cs deleted file mode 100644 index 41b857cd7..000000000 --- a/Cql/CqlSdkPrototype/Cql/Extensibility/CqlApiStateEntry.cs +++ /dev/null @@ -1,9 +0,0 @@ -using CqlSdkPrototype.Infrastructure; -using Hl7.Cql.CqlToElm; -using Hl7.Cql.Elm; - -namespace CqlSdkPrototype.Cql.Extensibility; - -public readonly record struct CqlApiStateEntry(CqlLibraryString CqlLibraryString, Library? ElmLibrary = null) { - internal LibraryBuilder? ElmLibraryBuilder { get; init; } -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql/Extensibility/ICqlApiExtendable.cs b/Cql/CqlSdkPrototype/Cql/Extensibility/ICqlApiExtendable.cs deleted file mode 100644 index fd4f83f14..000000000 --- a/Cql/CqlSdkPrototype/Cql/Extensibility/ICqlApiExtendable.cs +++ /dev/null @@ -1,14 +0,0 @@ -using CqlSdkPrototype.Infrastructure; - -namespace CqlSdkPrototype.Cql.Extensibility; - -public interface ICqlApiExtendable - where TCqlApi : ICqlApiExtendable -{ - ILoggerFactory LoggerFactory { get; } - CqlApiOptions Options { get; } - IReadOnlyDictionary Entries { get; } - TCqlApi WithOptions(Func replaceOptions); - TCqlApi AddCqlLibraries(IEnumerable libraries); - TCqlApi Translate(); -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql/Extensions/CqlApiExtensions.Adding.cs b/Cql/CqlSdkPrototype/Cql/Extensions/CqlApiExtensions.Adding.cs deleted file mode 100644 index 7b323b3e5..000000000 --- a/Cql/CqlSdkPrototype/Cql/Extensions/CqlApiExtensions.Adding.cs +++ /dev/null @@ -1,46 +0,0 @@ -using CqlSdkPrototype.Cql.Extensibility; -using CqlSdkPrototype.Infrastructure; -using CqlSdkPrototype.Internal; - -namespace CqlSdkPrototype.Cql.Extensions; - -public static partial class CqlApiExtensions -{ - public static TCqlApi AddCqlLibraryString( - this TCqlApi cqlApi, - CqlLibraryString cqlLibrary) - where TCqlApi : ICqlApiExtendable - { - return cqlApi.AddCqlLibraries([cqlLibrary]); - } - - public static TCqlApi AddCqlLibrariesFromDirectory( - this TCqlApi cqlApi, - DirectoryInfo directory, - EnumerationOptions? options = null, - Func? filePredicate = null) - where TCqlApi : ICqlApiExtendable - { - var files = directory.EnumerateFiles("*.cql", options ?? InternalConstants.DefaultEnumerationOptions); - if (filePredicate is not null) files = files.Where(filePredicate); - return cqlApi.AddCqlLibraryFiles(files); - } - - public static TCqlApi AddCqlLibraryFiles( - this TCqlApi cqlApi, - IEnumerable files) - where TCqlApi : ICqlApiExtendable - { - var logger = cqlApi.LoggerFactory.CreateLogger(typeof(CqlApiExtensions)); - var cqlLibraries = files - .Select(f => - { - logger.LogInformation("Loading library from file: {file}", f); - var cqlContent = File.ReadAllText(f.FullName); - var cqlLibrary = CqlLibraryString.Parse(cqlContent); - return cqlLibrary; - }); // Log errors - - return cqlApi.AddCqlLibraries(cqlLibraries); - } -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql/Extensions/CqlApiExtensions.cs b/Cql/CqlSdkPrototype/Cql/Extensions/CqlApiExtensions.cs deleted file mode 100644 index e635ea282..000000000 --- a/Cql/CqlSdkPrototype/Cql/Extensions/CqlApiExtensions.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace CqlSdkPrototype.Cql.Extensions; - -public static partial class CqlApiExtensions -{ - // This file is intentionally left blank - since it's the parent file for nested CqlApiExtensions.* files -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql/Internal/CqlApiInternalExtensions.cs b/Cql/CqlSdkPrototype/Cql/Internal/CqlApiInternalExtensions.cs deleted file mode 100644 index 6efe08946..000000000 --- a/Cql/CqlSdkPrototype/Cql/Internal/CqlApiInternalExtensions.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace CqlSdkPrototype.Cql.Internal; - -internal static class CqlApiInternalExtensions -{ - internal static ICqlApiInternal AsInternal(this ICqlApiInternal self) - where TCqlApi : ICqlApiInternal => self; -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql/Internal/CqlApiServices.cs b/Cql/CqlSdkPrototype/Cql/Internal/CqlApiServices.cs deleted file mode 100644 index 4395fb603..000000000 --- a/Cql/CqlSdkPrototype/Cql/Internal/CqlApiServices.cs +++ /dev/null @@ -1,81 +0,0 @@ -using CqlSdkPrototype.Internal; -using CqlSdkPrototype.Logging.Internal; -using Hl7.Cql.CqlToElm; -using Hl7.Cql.Elm; -using Hl7.Cql.Model; -using Hl7.Cql.Runtime.Hosting; -using ExpressionVisitor = Hl7.Cql.CqlToElm.Visitors.ExpressionVisitor; - -namespace CqlSdkPrototype.Cql.Internal; - -internal readonly record struct CqlApiServices( - ILoggerFactory LoggerFactory, - ServiceProvider ServiceProvider, - CqlToElmConverter CqlToElmConverter, - EntriesBuilderLibraryProvider LibraryProvider) -{ - private static readonly (CqlModel CqlModel, ModelInfo ModelInfo)[] AllMappedModelsInOrder = [ - (CqlModel.ElmR1, Models.ElmR1), - (CqlModel.Fhir401, Models.Fhir401)]; - - public static CqlApiServices Create(ILoggerFactory loggerFactory, CqlApiOptions options, EntriesBuilderLibraryProvider libraryProvider) - { - var services = new ServiceCollection(); - services.AddExternalLogging(loggerFactory); - AddCqlServices(services, options, libraryProvider); - var serviceProvider = services.BuildServiceProvider(validateScopes: true); - var cqlToElmConverter = serviceProvider.GetCqlToElmConverter(); - - return new CqlApiServices( - loggerFactory, - serviceProvider, - cqlToElmConverter, - libraryProvider); - } - - private static void AddCqlServices( - IServiceCollection serviceCollection, - CqlApiOptions options, - ILibraryProvider libraryProvider) - { - SuppressCqlDebugAssertions(); - - serviceCollection - .AddCqlToElmServices() - .AddCqlToElmModels(ConfigureModelProvider()) - .AddCqlToElmOptions(ConfigureCqlToElmOptions()) - .AddSingleton(libraryProvider) - .AddCqlToElmMessaging(); - return; - - Action ConfigureCqlToElmOptions() - { - return options.ApplyToCqlToElmOptions; - } - - Action ConfigureModelProvider() - { - var modelInfos = AllMappedModelsInOrder - .SelectWhereNotNull(t => options.Models.Contains(t.CqlModel) ? t.ModelInfo : null) - .Concat(options.ModelInfos); - return modelProvider => - { - foreach (var modelInfo in modelInfos) - modelProvider.Add(modelInfo); - }; - } - } - - private static void SuppressCqlDebugAssertions() - { - // This is really annoying in debug mode - ExpressionVisitor.EnableDebugAssertions = false; - Library.EnableDebugAssertions = false; - } - - public ILoggerFactory LoggerFactory { get; } = LoggerFactory; - public ServiceProvider ServiceProvider { get; } = ServiceProvider!; - public ILogger Logger { get; } = ServiceProvider.GetLogger(); - public CqlToElmConverter CqlToElmConverter { get; } = CqlToElmConverter!; - public EntriesBuilderLibraryProvider LibraryProvider { get; } = LibraryProvider!; -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql/Internal/CqlServicesOptions.cs b/Cql/CqlSdkPrototype/Cql/Internal/CqlServicesOptions.cs deleted file mode 100644 index f4b61bf35..000000000 --- a/Cql/CqlSdkPrototype/Cql/Internal/CqlServicesOptions.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Hl7.Cql.Model; - -namespace CqlSdkPrototype.Cql.Internal; - -internal class CqlServicesOptions -{ - public ModelInfo[] Models { get; set; } = []; -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql/Internal/CqlToElmTranslatorServices.cs b/Cql/CqlSdkPrototype/Cql/Internal/CqlToElmTranslatorServices.cs new file mode 100644 index 000000000..0fa6a1085 --- /dev/null +++ b/Cql/CqlSdkPrototype/Cql/Internal/CqlToElmTranslatorServices.cs @@ -0,0 +1,114 @@ +using CqlSdkPrototype.Internal; +using Hl7.Cql.CqlToElm; +using Hl7.Cql.Elm; +using Hl7.Cql.Model; +using ExpressionVisitor = Hl7.Cql.CqlToElm.Visitors.ExpressionVisitor; + +namespace CqlSdkPrototype.Cql.Internal; + +/// +/// Services for translating CQL to ELM used by the . +/// +internal readonly record struct CqlToElmTranslatorServices( + ILoggerFactory LoggerFactory, + ServiceProvider ServiceProvider, + CqlToElmConverter CqlToElmConverter, + LibraryBuilderProvider LibraryBuilderProvider) +{ + private static readonly (CqlModel CqlModel, ModelInfo ModelInfo)[] AllMappedModelsInOrder = [ + (CqlModel.ElmR1, Models.ElmR1), + (CqlModel.Fhir401, Models.Fhir401)]; + + /// + /// Creates an instance of . + /// + /// The logger factory. + /// The configuration for the translator. + /// The translation dictionary. + /// A new instance of . + public static CqlToElmTranslatorServices Create( + ILoggerFactory loggerFactory, + CqlToElmTranslatorConfig config, + CqlToElmTranslationDictionary translations) + { + var translationsBuilder = translations.ToBuilder(); + var libraryBuilderProvider = new LibraryBuilderProvider(translationsBuilder); + + var services = new ServiceCollection(); + services.AddExternalLogging(loggerFactory); + AddCqlServices(services, config, libraryBuilderProvider); + var serviceProvider = services.BuildServiceProvider(validateScopes: true); + + return ActivatorUtilities.CreateInstance(serviceProvider, serviceProvider, libraryBuilderProvider); + } + + /// + /// Adds CQL services to the service collection. + /// + /// The service collection. + /// The configuration for the translator. + /// The library provider. + private static void AddCqlServices( + IServiceCollection serviceCollection, + CqlToElmTranslatorConfig config, + ILibraryProvider libraryProvider) + { + SuppressCqlDebugAssertions(); + + serviceCollection + .AddCqlToElmServices() + .AddCqlToElmModels(ConfigureModelProvider()) + .AddCqlToElmOptions(ConfigureCqlToElmOptions()) + .AddSingleton(libraryProvider) + .AddCqlToElmMessaging(); + return; + + Action ConfigureCqlToElmOptions() + { + return config.ApplyToCqlToElmOptions; + } + + Action ConfigureModelProvider() + { + var modelInfos = AllMappedModelsInOrder + .SelectWhereNotNull(t => config.Models.Contains(t.CqlModel) ? t.ModelInfo : null) + .Concat(config.ModelInfos); + return modelProvider => + { + foreach (var modelInfo in modelInfos) + modelProvider.Add(modelInfo); + }; + } + } + + /// + /// Suppresses CQL debug assertions. + /// + private static void SuppressCqlDebugAssertions() + { + // This is really annoying in debug mode + ExpressionVisitor.EnableDebugAssertions = false; + Library.EnableDebugAssertions = false; + } + + /// + /// Gets the logger factory. + /// + public ILoggerFactory LoggerFactory { get; } = LoggerFactory; + /// + /// Gets the service provider. + /// + public ServiceProvider ServiceProvider { get; } = ServiceProvider!; + /// + /// Gets the logger for the CQL to ELM translator. + /// + public ILogger Logger { get; } = LoggerFactory.CreateLogger(); + /// + /// Gets the CQL to ELM converter. + /// + public CqlToElmConverter CqlToElmConverter { get; } = CqlToElmConverter!; + /// + /// Gets the library builder provider. + /// + public LibraryBuilderProvider LibraryBuilderProvider { get; } = LibraryBuilderProvider!; +} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql/Internal/ICqlApiInternal.cs b/Cql/CqlSdkPrototype/Cql/Internal/ICqlApiInternal.cs deleted file mode 100644 index 63f2c239d..000000000 --- a/Cql/CqlSdkPrototype/Cql/Internal/ICqlApiInternal.cs +++ /dev/null @@ -1,12 +0,0 @@ -using CqlSdkPrototype.Cql.Extensibility; - -namespace CqlSdkPrototype.Cql.Internal; - -/// -/// Used to gain internal access to the state of the CQL API. -/// -internal interface ICqlApiInternal : ICqlApiExtendable - where TCqlApi : ICqlApiExtendable -{ - CqlApiServices Services { get; } -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Cql/Internal/EntriesBuilderLibraryProvider.cs b/Cql/CqlSdkPrototype/Cql/Internal/LibraryBuilderProvider.cs similarity index 51% rename from Cql/CqlSdkPrototype/Cql/Internal/EntriesBuilderLibraryProvider.cs rename to Cql/CqlSdkPrototype/Cql/Internal/LibraryBuilderProvider.cs index d5777fc7b..6ecae10d0 100644 --- a/Cql/CqlSdkPrototype/Cql/Internal/EntriesBuilderLibraryProvider.cs +++ b/Cql/CqlSdkPrototype/Cql/Internal/LibraryBuilderProvider.cs @@ -3,10 +3,15 @@ namespace CqlSdkPrototype.Cql.Internal; -internal class EntriesBuilderLibraryProvider(CqlApiStateEntryDictionary.Builder entriesBuilder) +/// +/// Provides the implementation for +/// which resolves a given a library name and version on a . +/// +/// +internal sealed class LibraryBuilderProvider(CqlToElmTranslationDictionary.Builder translationsBuilder) : ILibraryProvider { - public CqlApiStateEntryDictionary.Builder EntriesBuilder { get; set; } = entriesBuilder; + public CqlToElmTranslationDictionary.Builder TranslationsBuilder { get; set; } = translationsBuilder; public bool TryResolveLibrary( string libraryName, @@ -21,7 +26,8 @@ public bool TryResolveLibrary( CqlLibraryIdentifier.Parse(libraryName), version is null ? null : CqlLibraryVersion.Parse(version)); - if (EntriesBuilder.TryGetValue(libVer, out var entry) && entry.ElmLibraryBuilder is { } lb) + if (TranslationsBuilder.TryGetValue(libVer, out var processItem) + && processItem.ElmLibraryBuilder is { } lb) { libraryBuilder = lb; return true; diff --git a/Cql/CqlSdkPrototype/CqlSdkPrototype.csproj b/Cql/CqlSdkPrototype/CqlSdkPrototype.csproj index 51629cd31..3f9e208e9 100644 --- a/Cql/CqlSdkPrototype/CqlSdkPrototype.csproj +++ b/Cql/CqlSdkPrototype/CqlSdkPrototype.csproj @@ -3,7 +3,7 @@ - Exe + Library net8.0 enable enable @@ -31,8 +31,4 @@ - - - - diff --git a/Cql/CqlSdkPrototype/Elm.Fluent/Extensions/FluentCqlToolkitExtensions.cs b/Cql/CqlSdkPrototype/Elm.Fluent/Extensions/FluentCqlToolkitExtensions.cs new file mode 100644 index 000000000..acfaa72a8 --- /dev/null +++ b/Cql/CqlSdkPrototype/Elm.Fluent/Extensions/FluentCqlToolkitExtensions.cs @@ -0,0 +1,23 @@ +using CqlSdkPrototype.Cql.Fluent; + +namespace CqlSdkPrototype.Elm.Fluent.Extensions; + +public static class FluentCqlToolkitExtensions +{ + public static FluentElmToolkit ToFluentElmToolkit( + this FluentCqlToolkit cqlToolkit, + Func? configure = null) + { + var config = new ElmToAssemblyCompilerConfig(ProcessBatchItemExceptionHandling: cqlToolkit.Config.ProcessBatchItemExceptionHandling); + if (configure is not null) config = configure(config); + var elmToolkit = new FluentElmToolkit(cqlToolkit.LoggerFactory, config).AddElmFromFluentCqlToolkit(cqlToolkit); + return elmToolkit; + } + + public static FluentElmToolkit CompileCqlToAssemblies( + this FluentCqlToolkit cqlToolkit) => + cqlToolkit + .TranslateCqlToElm() + .ToFluentElmToolkit() + .CompileElmToAssemblies(); +} diff --git a/Cql/CqlSdkPrototype/Elm.Fluent/Extensions/FluentElmToolkitExtensions.Adding.cs b/Cql/CqlSdkPrototype/Elm.Fluent/Extensions/FluentElmToolkitExtensions.Adding.cs new file mode 100644 index 000000000..7214356d0 --- /dev/null +++ b/Cql/CqlSdkPrototype/Elm.Fluent/Extensions/FluentElmToolkitExtensions.Adding.cs @@ -0,0 +1,84 @@ +using CqlSdkPrototype.Cql.Fluent; +using CqlSdkPrototype.Infrastructure; +using CqlSdkPrototype.Internal; +using Hl7.Cql.Elm; + +#pragma warning disable RS0027 + +namespace CqlSdkPrototype.Elm.Fluent.Extensions; + +public static partial class FluentElmToolkitExtensions +{ + public static FluentElmToolkit AddElmFromFluentCqlToolkit( + this FluentElmToolkit elmToolkit, + FluentCqlToolkit cqlToolkit) => + elmToolkit.AddElmLibraries( + from entry in cqlToolkit.CqlToElmTranslations + let elmLibrary = entry.Value.ElmLibrary + where elmLibrary is not null + select elmLibrary); + + public static FluentElmToolkit AddElmFileInDirectory( + this FluentElmToolkit elmToolkit, + DirectoryInfo directory, + CqlVersionedLibraryIdentifier versionedLibraryIdentifier) + { + FileInfo file = new(Path.Combine(directory.FullName, $"{versionedLibraryIdentifier}.json")); + if (file.Exists) + { + return elmToolkit.AddElmFile(file); + } + + if (versionedLibraryIdentifier.Version is null) + throw new FileNotFoundException($"Could not find file '{file.FullName}'."); + + var logger = elmToolkit.LoggerFactory.CreateLogger(typeof(FluentElmToolkitExtensions)); + logger.LogWarning("Could not load library from file with name and version, trying without version: {file}", file.FullName); + file = new FileInfo(Path.Combine(directory.FullName, $"{versionedLibraryIdentifier with { Version = null }}.json")); + return elmToolkit.AddElmFile(file); + } + + public static FluentElmToolkit AddElmFiles( + this FluentElmToolkit elmToolkit, + IEnumerable files) + { + var logger = elmToolkit.LoggerFactory.CreateLogger(typeof(FluentElmToolkitExtensions)); + var libraries = files + .Select(f => + { + logger.LogInformation("Loading library from file: {file}", f); + var library = Library.LoadFromJson(f); + return library; + }); // Log errors + return elmToolkit.AddElmLibraries(libraries); + } + + public static FluentElmToolkit AddElmFilesFromDirectory( + this FluentElmToolkit elmToolkit, + DirectoryInfo directory, + EnumerationOptions? options = null, + Func? filePredicate = null) + { + var files = directory.EnumerateFiles("*.json", options ?? InternalConstants.DefaultEnumerationOptions); + if (filePredicate is not null) files = files.Where(filePredicate); + return elmToolkit.AddElmFiles(files); + } + + public static FluentElmToolkit AddElmFileWithDependencies( + this FluentElmToolkit elmToolkit, + FileInfo file, + EnumerationOptions? options) => + throw new NotImplementedException(); + + public static FluentElmToolkit AddElmFileWithDependencies( + this FluentElmToolkit elmToolkit, + DirectoryInfo directory, + CqlVersionedLibraryIdentifier fileName, + EnumerationOptions? options) => + throw new NotImplementedException(); + + public static FluentElmToolkit AddElmFile( + this FluentElmToolkit elmToolkit, + FileInfo file) => + elmToolkit.AddElmFiles([file]); +} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Elm/Extensions/ElmApiExtensions.Saving.cs b/Cql/CqlSdkPrototype/Elm.Fluent/Extensions/FluentElmToolkitExtensions.Saving.cs similarity index 65% rename from Cql/CqlSdkPrototype/Elm/Extensions/ElmApiExtensions.Saving.cs rename to Cql/CqlSdkPrototype/Elm.Fluent/Extensions/FluentElmToolkitExtensions.Saving.cs index 938044116..f745469db 100644 --- a/Cql/CqlSdkPrototype/Elm/Extensions/ElmApiExtensions.Saving.cs +++ b/Cql/CqlSdkPrototype/Elm.Fluent/Extensions/FluentElmToolkitExtensions.Saving.cs @@ -1,21 +1,17 @@ -using CqlSdkPrototype.Elm.Extensibility; +namespace CqlSdkPrototype.Elm.Fluent.Extensions; -namespace CqlSdkPrototype.Elm.Extensions; - -public static partial class ElmApiExtensions +public static partial class FluentElmToolkitExtensions { - - public static TElmApi SaveCSharpFilesToDirectory( - this TElmApi elmApi, + public static FluentElmToolkit SaveCSharpFilesToDirectory( + this FluentElmToolkit elmToolkit, DirectoryInfo directory) - where TElmApi : IElmApiExtendable { if (!directory.Exists) directory.Create(); - var logger = elmApi.LoggerFactory.CreateLogger(typeof(ElmApiExtensions)); + var logger = elmToolkit.LoggerFactory.CreateLogger(typeof(FluentElmToolkitExtensions)); - foreach (var (libraryName, (_, cSharpSourceCode, _, _)) in elmApi.Entries) + foreach (var (libraryName, (_, cSharpSourceCode, _, _)) in elmToolkit.ElmToAssemblyCompilations) { if (cSharpSourceCode is null) continue; @@ -25,20 +21,19 @@ public static TElmApi SaveCSharpFilesToDirectory( logger.LogInformation("Saved C# source code to file: {file}", fileName); } - return elmApi; + return elmToolkit; } - public static TElmApi SaveAssemblyBinariesToDirectory( - this TElmApi elmApi, + public static FluentElmToolkit SaveAssemblyBinariesToDirectory( + this FluentElmToolkit elmToolkit, DirectoryInfo directory) - where TElmApi : IElmApiExtendable { if (!directory.Exists) directory.Create(); - var logger = elmApi.LoggerFactory.CreateLogger(typeof(ElmApiExtensions)); + var logger = elmToolkit.LoggerFactory.CreateLogger(typeof(FluentElmToolkitExtensions)); - foreach (var (libraryName, (_, _, assemblyBytes, symbolsBytes)) in elmApi.Entries) + foreach (var (libraryName, (_, _, assemblyBytes, symbolsBytes)) in elmToolkit.ElmToAssemblyCompilations) { if (assemblyBytes is null) continue; @@ -55,7 +50,6 @@ public static TElmApi SaveAssemblyBinariesToDirectory( } } - return elmApi; + return elmToolkit; } - } \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Elm.Fluent/Extensions/FluentElmToolkitExtensions.cs b/Cql/CqlSdkPrototype/Elm.Fluent/Extensions/FluentElmToolkitExtensions.cs new file mode 100644 index 000000000..3ba09be75 --- /dev/null +++ b/Cql/CqlSdkPrototype/Elm.Fluent/Extensions/FluentElmToolkitExtensions.cs @@ -0,0 +1,27 @@ +using Hl7.Cql.Abstractions.Exceptions; +using Hl7.Cql.CodeGeneration.NET; + +namespace CqlSdkPrototype.Elm.Fluent.Extensions; + +public static partial class FluentElmToolkitExtensions +{ + public static FluentElmToolkit ConfigIgnoreExceptions(this FluentElmToolkit cqlToolkit, bool stopAfterFirstException = false) => + cqlToolkit.Reconfigure(o => o with + { + ProcessBatchItemExceptionHandling = stopAfterFirstException + ? ProcessBatchItemExceptionHandling.IgnoreExceptionAndBreak + : ProcessBatchItemExceptionHandling.IgnoreExceptionAndContinue + }); + + public static FluentElmToolkit ConfigAssemblyDebugInformationToEmbedded(this FluentElmToolkit cqlToolkit) => + cqlToolkit.Reconfigure(o => o with + { + AssemblyCompilerDebugInformationFormat = AssemblyCompilerDebugInformationFormat.Embedded + }); + + public static FluentElmToolkit ConfigAssemblyDebugInformationToPortablePdb(this FluentElmToolkit cqlToolkit) => + cqlToolkit.Reconfigure(o => o with + { + AssemblyCompilerDebugInformationFormat = AssemblyCompilerDebugInformationFormat.PortablePdb + }); +} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Elm.Fluent/FluentElmToolkit.cs b/Cql/CqlSdkPrototype/Elm.Fluent/FluentElmToolkit.cs new file mode 100644 index 000000000..56682c3f7 --- /dev/null +++ b/Cql/CqlSdkPrototype/Elm.Fluent/FluentElmToolkit.cs @@ -0,0 +1,83 @@ +using Hl7.Cql.Elm; + +namespace CqlSdkPrototype.Elm.Fluent; + +/// +/// Provides a fluent interface for working with the ElmToAssemblyCompiler. +/// +public sealed class FluentElmToolkit +{ + private readonly ElmToAssemblyCompiler elmToAssemblyCompiler; + + /// + /// Initializes a new instance of the class. + /// + /// The logger factory to use for logging. + /// The configuration settings for the compiler. + public FluentElmToolkit( + ILoggerFactory? loggerFactory = null, + ElmToAssemblyCompilerConfig? settings = null) : this(new ElmToAssemblyCompiler(loggerFactory, settings)) + { + } + + /// + /// Initializes a new instance of the class with the specified compiler. + /// + /// The compiler to use. + public FluentElmToolkit(ElmToAssemblyCompiler elmToAssemblyCompiler) + { + this.elmToAssemblyCompiler = elmToAssemblyCompiler; + } + + /// + /// Gets the service provider used by tests. + /// + internal ServiceProvider ServiceProvider => elmToAssemblyCompiler.ServiceProvider; + + /// + /// Gets the logger factory used by extensions. + /// + public ILoggerFactory LoggerFactory => elmToAssemblyCompiler.LoggerFactory; + + /// + /// Gets the configuration for the compiler. + /// + public ElmToAssemblyCompilerConfig ProcessorConfig => elmToAssemblyCompiler.Config; + + /// + /// Gets the dictionary of ELM to assembly compilations. + /// + public ElmToAssemblyCompilationReadOnlyDictionary ElmToAssemblyCompilations => elmToAssemblyCompiler.ElmToAssemblyCompilations; + + /// + /// Reconfigures the compiler with the specified configuration. + /// + /// A function that takes the current configuration and returns a new configuration. + /// The current instance of . + public FluentElmToolkit Reconfigure(Func configure) + { + elmToAssemblyCompiler.Reconfigure(configure(ProcessorConfig)); + return this; + } + + /// + /// Adds ELM libraries to the compiler. + /// + /// The libraries to add. + /// The current instance of . + public FluentElmToolkit AddElmLibraries(IEnumerable libraries) + { + elmToAssemblyCompiler.AddElmLibraries(libraries); + return this; + } + + /// + /// Compiles the ELM libraries into .NET assemblies. + /// + /// The current instance of . + public FluentElmToolkit CompileElmToAssemblies() + { + elmToAssemblyCompiler.CompileElmToAssemblies(); + return this; + } +} diff --git a/Cql/CqlSdkPrototype/Elm/ElmApi.cs b/Cql/CqlSdkPrototype/Elm/ElmApi.cs deleted file mode 100644 index 6ff3bdcc7..000000000 --- a/Cql/CqlSdkPrototype/Elm/ElmApi.cs +++ /dev/null @@ -1,236 +0,0 @@ -using CqlSdkPrototype.Elm.Extensibility; -using CqlSdkPrototype.Elm.Internal; -using CqlSdkPrototype.Infrastructure; -using CqlSdkPrototype.Internal; -using Hl7.Cql.Abstractions.Exceptions; -using Hl7.Cql.CodeGeneration.NET; -using Hl7.Cql.Compiler; -using Hl7.Cql.Elm; -using Hl7.Cql.Runtime; - -namespace CqlSdkPrototype.Elm; - -public class ElmApi : - IElmApiExtendable, - IElmApiInternal -{ - public ElmApi( - ILoggerFactory? loggerFactory = null, - ElmApiOptions? options = null) : this(ElmApiState.Create(loggerFactory ?? NullLoggerFactory.Instance, options ?? ElmApiOptions.Default)) { } - - internal ElmApi(ElmApiState state) => _state = state; // Might make this public later. Used for testing now. - - #region State - - private ElmApiState _state; - - ElmApiOptions IElmApiExtendable.Options => _state.Options; - IReadOnlyDictionary IElmApiExtendable.Entries => _state.Entries; - - private ElmApi WithEntries( - ElmApiStateEntryDictionary entries) - { - _state = _state with { Entries = entries }; - return this; - } - - public ElmApi WithOptions( - Func replaceOptions) - { - var newOptions = replaceOptions(_state.Options); - if (!ReferenceEquals(_state.Options, newOptions)) - _state = _state with { Options = newOptions }; - return this; - } - - TResult IElmApiExtendable.UseLogger(Func, TResult> action) => action(this, _state.Logger); - ElmApiState IElmApiInternal.State => _state; - ILoggerFactory IElmApiExtendable.LoggerFactory => _state.LoggerFactory; - - #endregion - - #region Input (ELM Libraries) - - public ElmApi AddElmLibraries(IEnumerable libraries) - { - var entries = _state.Entries.ToBuilder(); - var hasChanged = false; - foreach (var library in libraries) - { - var versionedIdentifier = CqlVersionedLibraryIdentifier.FromVersionedIdentifier(library.identifier); - - if (entries.TryGetValue(versionedIdentifier, out var existingVersionedIdentifier)) - { - _state.Logger.LogInformation("Skipping replacing library {existingVersionedIdentifier} to compiler with new library: {versionedIdentifier}, ", - existingVersionedIdentifier, versionedIdentifier); - continue; - } - - var libraryCompilation = new ElmApiStateEntry(library); - entries.Add(versionedIdentifier, libraryCompilation); - _state.Logger.LogInformation("Adding library to compiler: {versionedIdentifier}", versionedIdentifier); - hasChanged = true; - } - - return hasChanged - ? WithEntries(entries: entries.ToImmutable()) - : this; - } - - #endregion - - #region Processing - - public ElmApi Compile() - { - var entries = _state.Entries; - if (entries.Values.All(predicate: lc => lc is { AssemblyBinary: not null })) - return this; - - using var servicesScope = _state.CreateScopedState(); - var logger = _state.Logger; - logger.LogInformation(message: "Compiling ELM into C# and .NET Binaries"); - var exceptionHandling = _state.Options.ProcessBatchItemExceptionHandling; - var debugInformationFormat = _state.Options.AssemblyCompilerDebugInformationFormat; - AssemblyCompiler assemblyCompiler = _state.AssemblyCompiler; - LibrarySetCSharpCodeGenerator cSharpCodeProcessor = _state.LibrarySetCSharpCodeGenerator; - LibrarySetExpressionBuilder librarySetExpressionBuilderScoped = servicesScope.LibrarySetExpressionBuilder; - Library[] libraries = entries.Values.Select(selector: v => v.ElmLibrary).ToArray(); - LibrarySet librarySet = new LibrarySet(name: "", libraries: libraries); - - var removedLibraries = librarySet.RemoveLibrariesWithMissingDependencies(); - foreach (var (id, _) in removedLibraries) - logger.LogWarning(message: "Removed library with missing dependencies: {id}", args: id); - - LogExceptionMessageAction log = logger.GetLogExceptionMessageAction(exceptionHandling); - - var librarySetDefinitions = BuildLibrarySetDefinitions(librarySetExpressionBuilderScoped, librarySet, logger, log, exceptionHandling); - - var cSharps = GenerateCSharp(cSharpCodeProcessor, librarySet, librarySetDefinitions, logger, log, exceptionHandling); - - var assemblyDatas = CompileAssemblies(assemblyCompiler, librarySet, cSharps, debugInformationFormat, logger, log, exceptionHandling); - - var entriesBuilder = entries.ToBuilder(); - var hasChanged = UpdateStateEntries(assemblyDatas, entriesBuilder, logger); - return hasChanged ? WithEntries(entries: entriesBuilder.ToImmutable()) : this; - } - - private static bool UpdateStateEntries( - IEnumerable<(Library library, AssemblyDataWithSourceCode assemblyDataWithSourceCode)> assemblyDatas, - ElmApiStateEntryDictionary.Builder entriesBuilder, - ILogger logger) - { - bool hasChanged = false; - foreach (var (library, (assemblyBinary, sourceCodePerName, debugSymbols)) in assemblyDatas) - { - var elmVersionedIdentifier = CqlVersionedLibraryIdentifier.FromVersionedIdentifier(library.identifier); - var libraryCompilation = entriesBuilder[key: elmVersionedIdentifier]; - if (libraryCompilation.CSharpSourceCode is not null - || libraryCompilation.AssemblyBinary is not null) - { - logger.LogInformation(message: "Library already compiled: {versionedIdentifier}", args: elmVersionedIdentifier); - continue; - } - - var cSharpSourceCode = sourceCodePerName!.Values.Single(); // We always expect a single source file - libraryCompilation = libraryCompilation with - { - CSharpSourceCode = cSharpSourceCode, - AssemblyBinary = assemblyBinary, - DebugSymbolsBinary = debugSymbols, - }; - entriesBuilder[key: elmVersionedIdentifier] = libraryCompilation; - logger.LogInformation(message: "Library compiled: {versionedIdentifier}", args: elmVersionedIdentifier); - hasChanged = true; - } - - return hasChanged; - } - - private static IEnumerable<(Library library, AssemblyDataWithSourceCode assemblyDataWithSourceCode)> CompileAssemblies( - AssemblyCompiler assemblyCompiler, - LibrarySet librarySet, - IEnumerable<(Library library, string cSharp)> cSharps, - AssemblyCompilerDebugInformationFormat debugInformationFormat, - ILogger logger, - LogExceptionMessageAction log, - ProcessBatchItemExceptionHandling exceptionHandling) - { - var assemblyDatas = assemblyCompiler - .CompileDeferred(librarySet, cSharps, debugInformationFormat) - .Select(t => - { - var libraryName = t.library.identifier; - logger.LogInformation("Compiling assembly for library : {libraryName}", libraryName); - return t; - }) - .TryProcessEach(t => (t.library, assemblyDataWithSourceCode: t.generateAssemblyDataWithSourceCode())) - .WithEachException(t => - { - var libraryName = t.Input.library.identifier; - log(t.Exception, "Error compiling assembly for library: {libraryName}", libraryName); - }) - .HandleExceptions(exceptionHandling) - //.ToArray() - ; - return assemblyDatas; - } - - private static IEnumerable<(Library library, string cSharp)> GenerateCSharp( - LibrarySetCSharpCodeGenerator cSharpCodeProcessor, - LibrarySet librarySet, - DefinitionDictionary librarySetDefinitions, - ILogger logger, - LogExceptionMessageAction log, - ProcessBatchItemExceptionHandling exceptionHandling) - { - var cSharps = cSharpCodeProcessor - .GenerateCSharpDeferred(librarySet, librarySetDefinitions) - .Select(t => - { - var libraryName = t.library.identifier; - logger.LogInformation("Generating C# for library : {libraryName}", libraryName); - return t; - }) - .TryProcessEach(t => (t.library, cSharp: t.generateCSharp())) - .WithEachException(t => - { - var libraryName = t.Input.library.identifier; - log(t.Exception, "Error generating C# for library : {libraryName}", libraryName); - }) - .HandleExceptions(exceptionHandling); - return cSharps; - } - - private static DefinitionDictionary BuildLibrarySetDefinitions( - LibrarySetExpressionBuilder librarySetExpressionBuilderScoped, - LibrarySet librarySet, - ILogger logger, - LogExceptionMessageAction log, - ProcessBatchItemExceptionHandling exceptionHandling) - { - var libraryDefinitions = librarySetExpressionBuilderScoped - .ProcessLibrarySetDeferred(librarySet: librarySet) - .Select(t => - { - var libraryName = t.library.identifier; - logger.LogInformation("Generating definitions for library : {libraryName}", libraryName); - return t; - }) - .TryProcessEach(t => (t.library, cSharp: t.generateLibraryDefinitions)) - .WithEachException(t => - { - var libraryName = t.Input.library.identifier; - log(t.Exception, "Error generating definitions for library : {libraryName}", libraryName); - }) - .HandleExceptions(exceptionHandling); - - DefinitionDictionary librarySetDefinitions = new(); - foreach (var (_, generateLibraryDefinitions) in libraryDefinitions) - librarySetDefinitions.Merge(generateLibraryDefinitions()); - - return librarySetDefinitions; - } - - #endregion -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Elm/ElmApiOptions.cs b/Cql/CqlSdkPrototype/Elm/ElmApiOptions.cs deleted file mode 100644 index c2ede1695..000000000 --- a/Cql/CqlSdkPrototype/Elm/ElmApiOptions.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Hl7.Cql.Abstractions.Exceptions; -using Hl7.Cql.CodeGeneration.NET; - -namespace CqlSdkPrototype.Elm; - -public record ElmApiOptions( - ProcessBatchItemExceptionHandling ProcessBatchItemExceptionHandling = default, - AssemblyCompilerDebugInformationFormat AssemblyCompilerDebugInformationFormat = AssemblyCompilerDebugInformationFormat.None) -{ - public static ElmApiOptions Default { get; } = new(); -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Elm/ElmApiState.cs b/Cql/CqlSdkPrototype/Elm/ElmApiState.cs deleted file mode 100644 index b7cbdf3e2..000000000 --- a/Cql/CqlSdkPrototype/Elm/ElmApiState.cs +++ /dev/null @@ -1,99 +0,0 @@ -using CqlSdkPrototype.Elm.Extensibility; -using CqlSdkPrototype.Infrastructure; -using CqlSdkPrototype.Logging.Internal; -using Hl7.Cql.Abstractions; -using Hl7.Cql.CodeGeneration.NET; -using Hl7.Cql.Compiler; -using Hl7.Cql.Conversion; -using Hl7.Cql.Fhir; -using Hl7.Cql.Runtime.Hosting; -using Hl7.Fhir.Introspection; - -namespace CqlSdkPrototype.Elm; - -internal readonly record struct ElmApiState( - ILoggerFactory LoggerFactory, - ImmutableDictionary Entries, - ElmApiOptions Options, - ServiceProvider ServiceProvider, - ILogger Logger, - AssemblyCompiler AssemblyCompiler, - LibrarySetCSharpCodeGenerator LibrarySetCSharpCodeGenerator) -{ - public static ElmApiState Create( - ILoggerFactory loggerFactory, - ElmApiOptions options) - { - var entries = ImmutableDictionary.Empty.WithComparers(CqlVersionedLibraryIdentifier.IdentifierOnlyEqualityComparer); - return new ElmApiState(loggerFactory, entries, null!, null!, null!, null!, null!) - { - // Must be set through the property initializer, to ensure the services are created - Options = options - }; - } - - private readonly ElmApiOptions _options = Options; - - public ElmApiOptions Options - { - get => _options; - init - { - if (ReferenceEquals(_options, value)) - return; - - ServiceProvider?.Dispose(); - - _options = value; - - var services = new ServiceCollection(); - services.AddExternalLogging(LoggerFactory!); - AddCqlCodeGenerationServices(services); - ServiceProvider = services.BuildServiceProvider(validateScopes:true); - Logger = ServiceProvider.GetLogger(); - AssemblyCompiler = ServiceProvider.GetRequiredService(); - LibrarySetCSharpCodeGenerator = ServiceProvider.GetRequiredService(); - } - } - - public ILoggerFactory LoggerFactory { get; } = LoggerFactory; - - public ElmApiScopedState CreateScopedState() => new(ServiceProvider.CreateScope()); - - private static void AddCqlCodeGenerationServices(IServiceCollection services) - { - AddCqlCompilerServices(services); - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(); - } - - public static IServiceCollection AddCqlCompilerServices(IServiceCollection services) - { - services.TryAddSingleton(_ => Hl7.Fhir.Model.ModelInfo.ModelInspector); - services.TryAddSingleton(); - - const int cacheSize = 0; // TODO: Must move to configuration - services.TryAddSingleton(sp => - { - var modelInspector = sp.GetRequiredService(); - var logger = sp.GetLogger(); - var converter = FhirTypeConverter - .Create(modelInspector, cacheSize) - .UseLogger(logger); - converter.CaptureAvailableConverters(); - return converter; - }); - - services.TryAddSingleton(); - services.TryAddSingleton(); - services.TryAddSingleton(_ => ExpressionBuilderSettings.Default); // TODO: Must move to configuration - services.TryAddScoped(); - services.TryAddScoped(); - services.TryAddScoped(); - services.TryAddScoped(); - - return services; - } - -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Elm/ElmToAssemblyCompilation.cs b/Cql/CqlSdkPrototype/Elm/ElmToAssemblyCompilation.cs new file mode 100644 index 000000000..f94904691 --- /dev/null +++ b/Cql/CqlSdkPrototype/Elm/ElmToAssemblyCompilation.cs @@ -0,0 +1,21 @@ +using Hl7.Cql.CodeGeneration.NET; +using Hl7.Cql.Elm; + +namespace CqlSdkPrototype.Elm; + +/// +/// Represents the compilation result of an ELM library to an assembly. +/// +/// The input ELM library being compiled. +/// The output generated C# source code from the ELM library. +/// The output compiled assembly binary. +/// +/// The output debug symbols binary for the compiled assembly. +/// This is only emitted if +/// is set to . +/// +public readonly record struct ElmToAssemblyCompilation( + Library ElmLibrary, + string? CSharpSourceCode = null, + byte[]? AssemblyBinary = null, + byte[]? DebugSymbolsBinary = null); \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Elm/ElmToAssemblyCompiler.cs b/Cql/CqlSdkPrototype/Elm/ElmToAssemblyCompiler.cs new file mode 100644 index 000000000..40ca8ec67 --- /dev/null +++ b/Cql/CqlSdkPrototype/Elm/ElmToAssemblyCompiler.cs @@ -0,0 +1,299 @@ +using CqlSdkPrototype.Elm.Fluent; +using CqlSdkPrototype.Elm.Internal; +using CqlSdkPrototype.Infrastructure; +using CqlSdkPrototype.Internal; +using Hl7.Cql.Abstractions.Exceptions; +using Hl7.Cql.CodeGeneration.NET; +using Hl7.Cql.Compiler; +using Hl7.Cql.Elm; +using Hl7.Cql.Runtime; + +namespace CqlSdkPrototype.Elm; + +/// +/// Compiles ELM (Expression Logical Model) into .NET assemblies. +/// +public sealed class ElmToAssemblyCompiler +{ + /// + /// Initializes a new instance of the class. + /// + /// The logger factory to use for logging. + /// The configuration for the compiler. + public ElmToAssemblyCompiler( + ILoggerFactory? loggerFactory = null, + ElmToAssemblyCompilerConfig? config = null) + { + config ??= ElmToAssemblyCompilerConfig.Default; + loggerFactory ??= NullLoggerFactory.Instance; + LoggerFactory = loggerFactory; + _elmToAssemblyCompilations = ElmToAssemblyCompilationDictionary.Empty; + Config = config; + _services = ElmToAssemblyProcessorServices.Create(loggerFactory, config); + } + + private ElmToAssemblyCompilationDictionary _elmToAssemblyCompilations; + private ElmToAssemblyProcessorServices _services; + + /// + /// Gets the logger factory used by extensions via . + /// + internal ILoggerFactory LoggerFactory { get; } + + /// + /// Gets the service provider used by tests via . + /// + internal ServiceProvider ServiceProvider => _services.ServiceProvider; + + /// + /// Gets the configuration for the compiler. + /// + public ElmToAssemblyCompilerConfig Config { get; private set; } + + /// + /// Gets the dictionary of ELM to assembly compilations. + /// + public ElmToAssemblyCompilationReadOnlyDictionary ElmToAssemblyCompilations => _elmToAssemblyCompilations; + + /// + /// Sets the conversions for the ELM to assembly compilations. + /// + /// The dictionary of ELM to assembly compilations. + private void SetConversions( + ElmToAssemblyCompilationDictionary elmToAssemblyCompilations) + { + _elmToAssemblyCompilations = elmToAssemblyCompilations; + } + + /// + /// Reconfigures the compiler with the specified configuration. + /// + /// The new configuration for the compiler. + public void Reconfigure( + ElmToAssemblyCompilerConfig config) + { + if (Config == config) + return; + + _services.ServiceProvider.Dispose(); + Config = config; + _services = ElmToAssemblyProcessorServices.Create(LoggerFactory, config); + } + + /// + /// Adds ELM libraries to the compiler. + /// + /// The libraries to add. + public void AddElmLibraries(IEnumerable libraries) + { + var entries = _elmToAssemblyCompilations.ToBuilder(); + var hasChanged = false; + foreach (var library in libraries) + { + var versionedIdentifier = CqlVersionedLibraryIdentifier.FromVersionedIdentifier(library.identifier); + + if (entries.TryGetValue(versionedIdentifier, out var existingVersionedIdentifier)) + { + _services.Logger.LogInformation( + "Skipping replacing library {existingVersionedIdentifier} to compiler with new library: {versionedIdentifier}, ", + existingVersionedIdentifier, versionedIdentifier); + continue; + } + + var libraryCompilation = new ElmToAssemblyCompilation(library); + entries.Add(versionedIdentifier, libraryCompilation); + _services.Logger.LogInformation("Adding library to compiler: {versionedIdentifier}", versionedIdentifier); + hasChanged = true; + } + + if (hasChanged) + SetConversions(elmToAssemblyCompilations: entries.ToImmutable()); + } + + /// + /// Compiles the ELM libraries into .NET assemblies. + /// + public void CompileElmToAssemblies() + { + var entries = _elmToAssemblyCompilations; + if (entries.Values.All(predicate: lc => lc is { AssemblyBinary: not null })) return; + + using var servicesScope = _services.CreateScopedState(); + var logger = _services.Logger; + logger.LogInformation(message: "Compiling ELM into C# and .NET Binaries"); + var exceptionHandling = Config.ProcessBatchItemExceptionHandling; + var debugInformationFormat = Config.AssemblyCompilerDebugInformationFormat; + AssemblyCompiler assemblyCompiler = _services.AssemblyCompiler; + LibrarySetCSharpCodeGenerator cSharpCodeProcessor = _services.LibrarySetCSharpCodeGenerator; + LibrarySetExpressionBuilder librarySetExpressionBuilderScoped = servicesScope.LibrarySetExpressionBuilder; + Library[] libraries = entries.Values.Select(selector: v => v.ElmLibrary).ToArray(); + LibrarySet librarySet = new LibrarySet(name: "", libraries: libraries); + + var removedLibraries = librarySet.RemoveLibrariesWithMissingDependencies(); + foreach (var (id, _) in removedLibraries) + logger.LogWarning(message: "Removed library with missing dependencies: {id}", args: id); + + LogExceptionMessageAction log = logger.GetLogExceptionMessageAction(exceptionHandling); + + var librarySetDefinitions = BuildLibrarySetDefinitions(librarySetExpressionBuilderScoped, librarySet, logger, log, exceptionHandling); + + var cSharps = GenerateCSharp(cSharpCodeProcessor, librarySet, librarySetDefinitions, logger, log, exceptionHandling); + + var assemblyBinaries = CompileAssemblies(assemblyCompiler, librarySet, cSharps, debugInformationFormat, logger, log, exceptionHandling); + + var entriesBuilder = entries.ToBuilder(); + var hasChanged = UpdateStateEntries(assemblyBinaries, entriesBuilder, logger); + if (hasChanged) + SetConversions(elmToAssemblyCompilations: entriesBuilder.ToImmutable()); + } + + /// + /// Updates the state entries with the compiled assemblies. + /// + /// The compiled assemblies. + /// The builder for the entries dictionary. + /// The logger to use for logging. + /// if the state entries were updated; otherwise, . + private static bool UpdateStateEntries( + IEnumerable<(Library library, AssemblyBinaryWithSourceCode assemblyBinaryWithSourceCode)> assemblyBinaries, + ElmToAssemblyCompilationDictionary.Builder entriesBuilder, + ILogger logger) + { + bool hasChanged = false; + foreach (var (library, (assemblyBinary, sourceCodePerName, debugSymbols)) in assemblyBinaries) + { + var elmVersionedIdentifier = CqlVersionedLibraryIdentifier.FromVersionedIdentifier(library.identifier); + var libraryCompilation = entriesBuilder[key: elmVersionedIdentifier]; + if (libraryCompilation.CSharpSourceCode is not null + || libraryCompilation.AssemblyBinary is not null) + { + logger.LogInformation(message: "Library already compiled: {versionedIdentifier}", args: elmVersionedIdentifier); + continue; + } + + var cSharpSourceCode = sourceCodePerName!.Values.Single(); // We always expect a single source file + libraryCompilation = libraryCompilation with + { + CSharpSourceCode = cSharpSourceCode, + AssemblyBinary = assemblyBinary, + DebugSymbolsBinary = debugSymbols, + }; + entriesBuilder[key: elmVersionedIdentifier] = libraryCompilation; + logger.LogInformation(message: "Library compiled: {versionedIdentifier}", args: elmVersionedIdentifier); + hasChanged = true; + } + + return hasChanged; + } + + /// + /// Compiles the C# code into .NET assemblies. + /// + /// The assembly compiler to use. + /// The set of libraries to compile. + /// The C# code to compile. + /// The format for debug information. + /// The logger to use for logging. + /// The action to log exceptions. + /// The exception handling strategy. + /// The compiled assemblies. + private static IEnumerable<(Library library, AssemblyBinaryWithSourceCode assemblyBinaryWithSourceCode)> CompileAssemblies( + AssemblyCompiler assemblyCompiler, + LibrarySet librarySet, + IEnumerable<(Library library, string cSharp)> cSharps, + AssemblyCompilerDebugInformationFormat debugInformationFormat, + ILogger logger, + LogExceptionMessageAction log, + ProcessBatchItemExceptionHandling exceptionHandling) + { + var assemblyBinaries = assemblyCompiler + .CompileDeferred(librarySet, cSharps, debugInformationFormat) + .Select(t => + { + var libraryName = t.library.identifier; + logger.LogInformation("Compiling assembly for library : {libraryName}", libraryName); + return t; + }) + .TryProcessEach(t => (t.library, assemblyBinaryWithSourceCode: t.generateAssemblyBinaryWithSourceCode())) + .WithEachException(t => + { + var libraryName = t.Input.library.identifier; + log(t.Exception, "Error compiling assembly for library: {libraryName}", libraryName); + }) + .HandleExceptions(exceptionHandling); + return assemblyBinaries; + } + + /// + /// Generates the C# code for the libraries. + /// + /// The C# code processor to use. + /// The set of libraries to generate code for. + /// The definitions for the library set. + /// The logger to use for logging. + /// The action to log exceptions. + /// The exception handling strategy. + /// The generated C# code. + private static IEnumerable<(Library library, string cSharp)> GenerateCSharp( + LibrarySetCSharpCodeGenerator cSharpCodeProcessor, + LibrarySet librarySet, + DefinitionDictionary librarySetDefinitions, + ILogger logger, + LogExceptionMessageAction log, + ProcessBatchItemExceptionHandling exceptionHandling) + { + var cSharps = cSharpCodeProcessor + .GenerateCSharpDeferred(librarySet, librarySetDefinitions) + .Select(t => + { + var libraryName = t.library.identifier; + logger.LogInformation("Generating C# for library : {libraryName}", libraryName); + return t; + }) + .TryProcessEach(t => (t.library, cSharp: t.generateCSharp())) + .WithEachException(t => + { + var libraryName = t.Input.library.identifier; + log(t.Exception, "Error generating C# for library : {libraryName}", libraryName); + }) + .HandleExceptions(exceptionHandling); + return cSharps; + } + + /// + /// Builds the library set definitions. + /// + /// The library set expression builder to use. + /// The set of libraries to build definitions for. + /// The logger to use for logging. + /// The action to log exceptions. + /// The exception handling strategy. + /// The dictionary of library set definitions. + private static DefinitionDictionary BuildLibrarySetDefinitions( + LibrarySetExpressionBuilder librarySetExpressionBuilderScoped, + LibrarySet librarySet, + ILogger logger, + LogExceptionMessageAction log, + ProcessBatchItemExceptionHandling exceptionHandling) + { + DefinitionDictionary librarySetDefinitions = new(); + foreach (var (_, libraryDefinitions) in + librarySetExpressionBuilderScoped + .ProcessLibrarySetDeferred(librarySet: librarySet) + .Select(t => + { + var libraryName = t.library.identifier; + logger.LogInformation("Generating definitions for library : {libraryName}", libraryName); + return t; + }) + .TryProcessEach(t => (t.library, cSharp: t.generateLibraryDefinitions())) + .WithEachException(t => + { + var libraryName = t.Input.library.identifier; + log(t.Exception, "Error generating definitions for library : {libraryName}", libraryName); + }) + .HandleExceptions(exceptionHandling)) + librarySetDefinitions.Merge(libraryDefinitions); + return librarySetDefinitions; + } +} diff --git a/Cql/CqlSdkPrototype/Elm/ElmToAssemblyCompilerConfig.cs b/Cql/CqlSdkPrototype/Elm/ElmToAssemblyCompilerConfig.cs new file mode 100644 index 000000000..9e49adcac --- /dev/null +++ b/Cql/CqlSdkPrototype/Elm/ElmToAssemblyCompilerConfig.cs @@ -0,0 +1,78 @@ +using Hl7.Cql.Abstractions.Exceptions; +using Hl7.Cql.CodeGeneration.NET; +using Hl7.Cql.Compiler; + +namespace CqlSdkPrototype.Elm; + +/// +/// Configuration settings for the Elm to Assembly compiler. +/// +/// The exception handling policy to use while processing a batch of items. +/// The format of the debug information emitted by the compiler. +/// Allows a child scope to redefine an existing parent scope. Default is . +/// +/// When , functions declared external will throw at runtime +/// if they are not found in customImplementations. When , an +/// will be thrown during compilation if they are not found in customImplementations. +/// The default value is . +/// +/// The size of the Least Recently Used (LRU) cache. +public sealed record ElmToAssemblyCompilerConfig( + ProcessBatchItemExceptionHandling ProcessBatchItemExceptionHandling = default, + AssemblyCompilerDebugInformationFormat AssemblyCompilerDebugInformationFormat = AssemblyCompilerDebugInformationFormat.None, + bool AllowScopeRedefinition = true, + bool AllowUnresolvedExternals = true, + int LRUCacheSize = 0) +{ + /// + /// Gets the default configuration settings. + /// + public static ElmToAssemblyCompilerConfig Default { get; } = new(); + + /// + /// Allows a child scope to redefine an existing parent scope. Default is . + /// + /// + /// For example, consider this query: + /// + /// IinCC X + /// return + /// ( + /// Tuple + /// { + /// sdate: start of X, + /// edate: + /// end of X, + /// ndate: + /// end of X + System.Quantity { value: DDiff, unit: 'day' } + /// } + /// ) X + /// return Tuple + /// { + /// CInterval: Interval[X.sdate, X.edate], + /// RInterval: Interval[X.sdate, X.ndate] + /// } + /// + /// Here, X is being used twice, because the source is a subquery. X is used in the subquery and is also used + /// in the main query. ELM does not limit the scope of the first X to only the subquery as it probably should. + /// + public bool AllowScopeRedefinition { get; init; } = AllowScopeRedefinition; + + /// + /// When , functions declared external will throw at runtime + /// if they are not found in customImplementations. When , an + /// will be thrown during compilation if they are not found in customImplementations. + /// The default value is . + /// + public bool AllowUnresolvedExternals { get; init; } = AllowUnresolvedExternals; + + /// + /// Converts the current configuration settings to . + /// + /// An instance of with the current configuration settings. + internal ExpressionBuilderSettings ToExpressionBuilderSettings() => new() + { + AllowScopeRedefinition = AllowScopeRedefinition, + AllowUnresolvedExternals = AllowUnresolvedExternals + }; +} diff --git a/Cql/CqlSdkPrototype/Elm/Extensibility/ElmApiExtendableExtensions.cs b/Cql/CqlSdkPrototype/Elm/Extensibility/ElmApiExtendableExtensions.cs deleted file mode 100644 index 2487a6c02..000000000 --- a/Cql/CqlSdkPrototype/Elm/Extensibility/ElmApiExtendableExtensions.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace CqlSdkPrototype.Elm.Extensibility; - -public static class ElmApiExtendableExtensions -{ - public static IElmApiExtendable AsExtendable(this ElmApi self) => self; -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Elm/Extensibility/ElmApiStateEntry.cs b/Cql/CqlSdkPrototype/Elm/Extensibility/ElmApiStateEntry.cs deleted file mode 100644 index 53c85fa6a..000000000 --- a/Cql/CqlSdkPrototype/Elm/Extensibility/ElmApiStateEntry.cs +++ /dev/null @@ -1,6 +0,0 @@ -using Hl7.Cql.Elm; - -namespace CqlSdkPrototype.Elm.Extensibility; - -public readonly record struct ElmApiStateEntry - (Library ElmLibrary, string? CSharpSourceCode = null, byte[]? AssemblyBinary = null, byte[]? DebugSymbolsBinary = null); \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Elm/Extensibility/IElmApiExtendable.cs b/Cql/CqlSdkPrototype/Elm/Extensibility/IElmApiExtendable.cs deleted file mode 100644 index 35fd1f0fd..000000000 --- a/Cql/CqlSdkPrototype/Elm/Extensibility/IElmApiExtendable.cs +++ /dev/null @@ -1,16 +0,0 @@ -using CqlSdkPrototype.Infrastructure; -using Hl7.Cql.Elm; - -namespace CqlSdkPrototype.Elm.Extensibility; - -public interface IElmApiExtendable - where TElmApi : IElmApiExtendable -{ - ILoggerFactory LoggerFactory { get; } - ElmApiOptions Options { get; } - IReadOnlyDictionary Entries { get; } - TElmApi WithOptions(Func replaceOptions); - TElmApi AddElmLibraries(IEnumerable libraries); - TElmApi Compile(); - TResult UseLogger(Func, TResult> action); // Useful for extensions methods -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Elm/Extensions/ElmApiExtensions.Adding.cs b/Cql/CqlSdkPrototype/Elm/Extensions/ElmApiExtensions.Adding.cs deleted file mode 100644 index ac12e0c61..000000000 --- a/Cql/CqlSdkPrototype/Elm/Extensions/ElmApiExtensions.Adding.cs +++ /dev/null @@ -1,103 +0,0 @@ -using CqlSdkPrototype.Cql.Extensibility; -using CqlSdkPrototype.Elm.Extensibility; -using CqlSdkPrototype.Infrastructure; -using CqlSdkPrototype.Internal; -using Hl7.Cql.Elm; - -#pragma warning disable RS0027 - -namespace CqlSdkPrototype.Elm.Extensions; - -public static partial class ElmApiExtensions -{ - public static TElmApi AddElmFromCqlApi( - this TElmApi elmApi, - TCqlApi cqlApi) - where TElmApi : IElmApiExtendable - where TCqlApi : ICqlApiExtendable - { - return elmApi.AddElmLibraries( - from entry in cqlApi.Entries - let elmLibrary = entry.Value.ElmLibrary - where elmLibrary is not null - select elmLibrary); - } - - public static TElmApi AddElmFile( - this TElmApi elmApi, - DirectoryInfo directory, - CqlVersionedLibraryIdentifier versionedLibraryIdentifier) - where TElmApi : IElmApiExtendable - { - FileInfo file = new(Path.Combine(directory.FullName, $"{versionedLibraryIdentifier}.json")); - if (file.Exists) - return elmApi.AddElmFile(file); - - if (versionedLibraryIdentifier.Version is null) - throw new FileNotFoundException($"Could not find file '{file.FullName}'."); - - return elmApi.UseLogger((elmApi, logger) => - { - logger.LogWarning("Could not load library from file with name and version, trying without version: {file}", file.FullName); - file = new FileInfo(Path.Combine(directory.FullName, $"{versionedLibraryIdentifier with { Version = null }}.json")); - return elmApi.AddElmFile(file); - }); - } - - public static TElmApi AddElmFiles( - this TElmApi elmApi, - IEnumerable files) - where TElmApi : IElmApiExtendable - { - var logger = elmApi.LoggerFactory.CreateLogger(typeof(ElmApiExtensions)); - var libraries = files - .Select(f => - { - logger.LogInformation("Loading library from file: {file}", f); - var library = Library.LoadFromJson(f); - return library; - }); // Log errors - return elmApi.AddElmLibraries(libraries); - } - - public static TElmApi AddElmFilesFromDirectory( - this TElmApi elmApi, - DirectoryInfo directory, - EnumerationOptions? options = null, - Func? filePredicate = null) - where TElmApi : IElmApiExtendable - { - var files = directory.EnumerateFiles("*.json", options ?? InternalConstants.DefaultEnumerationOptions); - if (filePredicate is not null) files = files.Where(filePredicate); - return elmApi.AddElmFiles(files); - } - - public static TElmApi AddElmFileWithDependencies( - this TElmApi elmApi, - FileInfo file, - EnumerationOptions? options) - where TElmApi : IElmApiExtendable - { - // TODO - return elmApi; - } - - public static TElmApi AddElmFileWithDependencies( - this TElmApi elmApi, - DirectoryInfo directory, - CqlVersionedLibraryIdentifier fileName, - EnumerationOptions? options) - where TElmApi : IElmApiExtendable - { - // TODO - return elmApi; - } - - public static TElmApi AddElmFile( - this TElmApi elmApi, - FileInfo file) - where TElmApi : IElmApiExtendable - { - return elmApi.AddElmFiles([file]); - } -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Elm/Extensions/ElmApiExtensions.Cql.cs b/Cql/CqlSdkPrototype/Elm/Extensions/ElmApiExtensions.Cql.cs deleted file mode 100644 index baa91288b..000000000 --- a/Cql/CqlSdkPrototype/Elm/Extensions/ElmApiExtensions.Cql.cs +++ /dev/null @@ -1,17 +0,0 @@ -using CqlSdkPrototype.Cql; -using CqlSdkPrototype.Runtime.Extensions; - -namespace CqlSdkPrototype.Elm.Extensions; - -public static partial class ElmApiExtensions -{ - public static ElmApi Compile( - this CqlApi cqlApi) - { - return cqlApi - .Translate() - .CreateElmApi() - .Compile(); - } - -} diff --git a/Cql/CqlSdkPrototype/Elm/Extensions/ElmApiExtensions.cs b/Cql/CqlSdkPrototype/Elm/Extensions/ElmApiExtensions.cs deleted file mode 100644 index fc12f32df..000000000 --- a/Cql/CqlSdkPrototype/Elm/Extensions/ElmApiExtensions.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace CqlSdkPrototype.Elm.Extensions; - -public static partial class ElmApiExtensions -{ - // This file is intentionally left blank - since it's the parent file for nested ElmApiExtensions.* files -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Elm/Internal/ElmApiInternalExtensions.cs b/Cql/CqlSdkPrototype/Elm/Internal/ElmApiInternalExtensions.cs deleted file mode 100644 index 2ab55142e..000000000 --- a/Cql/CqlSdkPrototype/Elm/Internal/ElmApiInternalExtensions.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace CqlSdkPrototype.Elm.Internal; - -internal static class ElmApiInternalExtensions -{ - internal static IElmApiInternal AsInternal(this IElmApiInternal self) - where TElmApi : IElmApiInternal => self; -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Elm/ElmApiScopedState.cs b/Cql/CqlSdkPrototype/Elm/Internal/ElmApiScopedState.cs similarity index 65% rename from Cql/CqlSdkPrototype/Elm/ElmApiScopedState.cs rename to Cql/CqlSdkPrototype/Elm/Internal/ElmApiScopedState.cs index 973a89cc7..bdde96a4b 100644 --- a/Cql/CqlSdkPrototype/Elm/ElmApiScopedState.cs +++ b/Cql/CqlSdkPrototype/Elm/Internal/ElmApiScopedState.cs @@ -1,8 +1,8 @@ using Hl7.Cql.Compiler; -namespace CqlSdkPrototype.Elm; +namespace CqlSdkPrototype.Elm.Internal; -internal class ElmApiScopedState(IServiceScope scope) : IDisposable +internal sealed class ElmToolkitScopedState(IServiceScope scope) : IDisposable { public LibrarySetExpressionBuilder LibrarySetExpressionBuilder { get; } = scope.ServiceProvider.GetRequiredService(); diff --git a/Cql/CqlSdkPrototype/Elm/Internal/ElmToAssemblyProcessorServices.cs b/Cql/CqlSdkPrototype/Elm/Internal/ElmToAssemblyProcessorServices.cs new file mode 100644 index 000000000..c4abf4538 --- /dev/null +++ b/Cql/CqlSdkPrototype/Elm/Internal/ElmToAssemblyProcessorServices.cs @@ -0,0 +1,79 @@ +using CqlSdkPrototype.Internal; +using Hl7.Cql.Abstractions; +using Hl7.Cql.CodeGeneration.NET; +using Hl7.Cql.Compiler; +using Hl7.Cql.Conversion; +using Hl7.Cql.Fhir; +using Hl7.Cql.Runtime.Hosting; +using Hl7.Fhir.Introspection; + +namespace CqlSdkPrototype.Elm.Internal; + +internal readonly record struct ElmToAssemblyProcessorServices( + ServiceProvider ServiceProvider, + ILogger Logger, + AssemblyCompiler AssemblyCompiler, + LibrarySetCSharpCodeGenerator LibrarySetCSharpCodeGenerator) +{ + public static ElmToAssemblyProcessorServices Create( + ILoggerFactory loggerFactory, + ElmToAssemblyCompilerConfig config) + { + var services = new ServiceCollection(); + services.AddExternalLogging(loggerFactory); + AddCqlCodeGenerationServices(services, config); + var serviceProvider = services.BuildServiceProvider(validateScopes: true); + + return ActivatorUtilities.CreateInstance(serviceProvider, serviceProvider); + } + + private static void AddCqlCodeGenerationServices( + IServiceCollection services, + ElmToAssemblyCompilerConfig config) + { + var expressionBuilderSettings = config.ToExpressionBuilderSettings(); + AddCqlCompilerServices(services, config.LRUCacheSize, expressionBuilderSettings); + services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(); + } + + /// + /// Used by and by many test cases + /// + public static IServiceCollection AddCqlCompilerServices( + IServiceCollection services, + int lruCacheSize = 0, + ExpressionBuilderSettings? expressionBuilderSettings = null) + { + expressionBuilderSettings ??= ExpressionBuilderSettings.Default; + services.TryAddSingleton(_ => Hl7.Fhir.Model.ModelInfo.ModelInspector); + services.TryAddSingleton(); + + services.TryAddSingleton(sp => + { + var modelInspector = sp.GetRequiredService(); + var logger = sp.GetLogger(); + var converter = FhirTypeConverter + .Create(modelInspector, lruCacheSize) + .UseLogger(logger); + converter.CaptureAvailableConverters(); + return converter; + }); + + services.TryAddSingleton(); + services.TryAddSingleton(); + services.TryAddSingleton(_ => expressionBuilderSettings); + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + + return services; + } + + public ServiceProvider ServiceProvider { get; } = ServiceProvider; + public AssemblyCompiler AssemblyCompiler { get; } = AssemblyCompiler; + public LibrarySetCSharpCodeGenerator LibrarySetCSharpCodeGenerator { get; } = LibrarySetCSharpCodeGenerator; + public ElmToolkitScopedState CreateScopedState() => new(ServiceProvider.CreateScope()); +} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Elm/Internal/IElmApiInternal.cs b/Cql/CqlSdkPrototype/Elm/Internal/IElmApiInternal.cs deleted file mode 100644 index dacf01121..000000000 --- a/Cql/CqlSdkPrototype/Elm/Internal/IElmApiInternal.cs +++ /dev/null @@ -1,12 +0,0 @@ -using CqlSdkPrototype.Elm.Extensibility; - -namespace CqlSdkPrototype.Elm.Internal; - -/// -/// Used to gain internal access to the state of the ELM API. -/// -internal interface IElmApiInternal : IElmApiExtendable - where TElmApi : IElmApiExtendable -{ - ElmApiState State { get; } -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/GlobalUsings.cs b/Cql/CqlSdkPrototype/GlobalUsings.cs index 187b89bd2..d265a5b60 100644 --- a/Cql/CqlSdkPrototype/GlobalUsings.cs +++ b/Cql/CqlSdkPrototype/GlobalUsings.cs @@ -13,5 +13,9 @@ global using Microsoft.Extensions.DependencyInjection.Extensions; global using Microsoft.Extensions.Logging; global using Microsoft.Extensions.Logging.Abstractions; -global using CqlApiStateEntryDictionary = System.Collections.Immutable.ImmutableDictionary; -global using ElmApiStateEntryDictionary = System.Collections.Immutable.ImmutableDictionary; \ No newline at end of file +global using CqlToElmTranslationDictionary = System.Collections.Immutable.ImmutableDictionary; +global using CqlToElmTranslationReadOnlyDictionary = System.Collections.Generic.IReadOnlyDictionary; +global using ElmToAssemblyCompilationDictionary = System.Collections.Immutable.ImmutableDictionary; +global using ElmToAssemblyCompilationReadOnlyDictionary = System.Collections.Generic.IReadOnlyDictionary; +global using AssemblyBinaryHashSet = System.Collections.Immutable.ImmutableHashSet; +global using AssemblyBinaryReadOnlyHashSet = System.Collections.Generic.IReadOnlySet; \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Internal/InternalExtensions.cs b/Cql/CqlSdkPrototype/Internal/InternalExtensions.cs index e11a98c4a..c8b358681 100644 --- a/Cql/CqlSdkPrototype/Internal/InternalExtensions.cs +++ b/Cql/CqlSdkPrototype/Internal/InternalExtensions.cs @@ -4,23 +4,6 @@ namespace CqlSdkPrototype.Internal; internal static class InternalExtensions { - public static string[] SplitLines(this string multilineString) => - multilineString.Split([Environment.NewLine], StringSplitOptions.None); - - public static string Join(this IEnumerable lines) => - string.Concat(lines); - - public static string JoinLines(this IEnumerable lines) => - string.Join(Environment.NewLine, lines); - - public static string TakeLines(this string multilineString, int count) => - multilineString.SplitLines().Take(count).JoinLines(); - - public static string TrimFileExtension(this string filePath, string extension) => - filePath.EndsWith(extension, StringComparison.OrdinalIgnoreCase) - ? filePath[..^extension.Length] - : filePath; - public static Assembly LoadFromBytes(this AssemblyLoadContext assemblyLoadContext, byte[] assembly, byte[]? symbols = null) { using var assemblyStream = new MemoryStream(assembly); @@ -47,54 +30,6 @@ public static IEnumerable WhereNotNull(this IEnumerable enumerable) .Select(x => x!); } - public static bool IsBetween( - this Version value, - Version lowerIncl, - Version upperExcl) - { - return value >= lowerIncl && value < upperExcl; - } - - public static Maybe TryGetFirst(this IEnumerable source) - { - if (source == null) - throw new ArgumentNullException(nameof(source)); - - if (source is IList list) - { - if (list.Count > 0) - { - return list[0]; - } - } - else - { - using IEnumerator e = source.GetEnumerator(); - if (e.MoveNext()) - { - return e.Current; - } - } - - return Maybe.NoValue; - } - - public static Maybe TryGetFirst(this IEnumerable source, Func predicate) - { - if (source == null) - throw new ArgumentNullException(nameof(source)); - - foreach (TSource element in source) - { - if (predicate(element)) - { - return element; - } - } - - return Maybe.NoValue; - } - public static LogExceptionMessageAction GetLogExceptionMessageAction( this ILogger logger, ProcessBatchItemExceptionHandling exceptionHandling) => diff --git a/Cql/CqlSdkPrototype/Logging/Internal/LoggingServiceCollectionExtensions.cs b/Cql/CqlSdkPrototype/Internal/LoggingServiceCollectionExtensions.cs similarity index 90% rename from Cql/CqlSdkPrototype/Logging/Internal/LoggingServiceCollectionExtensions.cs rename to Cql/CqlSdkPrototype/Internal/LoggingServiceCollectionExtensions.cs index 43e3b3dab..289d0026a 100644 --- a/Cql/CqlSdkPrototype/Logging/Internal/LoggingServiceCollectionExtensions.cs +++ b/Cql/CqlSdkPrototype/Internal/LoggingServiceCollectionExtensions.cs @@ -1,4 +1,4 @@ -namespace CqlSdkPrototype.Logging.Internal; +namespace CqlSdkPrototype.Internal; internal static class LoggingServiceCollectionExtensions { diff --git a/Cql/CqlSdkPrototype/Invocation.Fluent/Extensions/FluentCqlToolkitExtensions.cs b/Cql/CqlSdkPrototype/Invocation.Fluent/Extensions/FluentCqlToolkitExtensions.cs new file mode 100644 index 000000000..39e27ae5c --- /dev/null +++ b/Cql/CqlSdkPrototype/Invocation.Fluent/Extensions/FluentCqlToolkitExtensions.cs @@ -0,0 +1,23 @@ +using CqlSdkPrototype.Cql.Fluent; +using CqlSdkPrototype.Elm; +using CqlSdkPrototype.Elm.Fluent.Extensions; + +namespace CqlSdkPrototype.Invocation.Fluent.Extensions; + +public static class FluentCqlToolkitExtensions +{ + +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters + public static LibrarySetInvoker ToLibrarySetInvoker( +#pragma warning restore RS0026 + this FluentCqlToolkit cqlToolkit, + Func? configureElmToAssemblySettings = null,/* + Func? configureLibrarySetInvokerBuilderSettings = null,*/ + string name = "") + { + return cqlToolkit + .TranslateCqlToElm() + .ToFluentElmToolkit(configureElmToAssemblySettings) + .ToLibrarySetInvoker(name/*, configureLibrarySetInvokerBuilderSettings*/); + } +} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Invocation.Fluent/Extensions/FluentElmToolkitExtensions.cs b/Cql/CqlSdkPrototype/Invocation.Fluent/Extensions/FluentElmToolkitExtensions.cs new file mode 100644 index 000000000..93fd1a880 --- /dev/null +++ b/Cql/CqlSdkPrototype/Invocation.Fluent/Extensions/FluentElmToolkitExtensions.cs @@ -0,0 +1,38 @@ +using CqlSdkPrototype.Elm.Fluent; + +namespace CqlSdkPrototype.Invocation.Fluent.Extensions; + +public static class FluentElmToolkitExtensions +{ + public static FluentInvocationToolkit ToFluentInvocationToolkit( + this FluentElmToolkit elmToolkit/*, + Func? configureLibrarySetInvokerBuilderSettings = null*/) + { + /*var config = LibrarySetInvokerBuilderConfig.Default; + if (configureLibrarySetInvokerBuilderSettings is not null) config = configureLibrarySetInvokerBuilderSettings(config);*/ + + var assemblyBinaries = + from entry in elmToolkit.ElmToAssemblyCompilations + let assembly = entry.Value.AssemblyBinary + where assembly is not null + let debugSymbols = entry.Value.DebugSymbolsBinary + let assemblyBinary = new Hl7.Cql.CodeGeneration.NET.AssemblyBinary(assembly, debugSymbols) + select assemblyBinary; + + var invocationToolkit = new FluentInvocationToolkit(elmToolkit.LoggerFactory/*, config*/).AddAssemblyBinaries(assemblyBinaries); + return invocationToolkit; + } + +#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters + public static LibrarySetInvoker ToLibrarySetInvoker( +#pragma warning restore RS0026 + this FluentElmToolkit elmToolkit, + string name = ""/*, + Func? configure = null*/) + { + return elmToolkit + .CompileElmToAssemblies() + .ToFluentInvocationToolkit(/*configure*/) + .ToLibrarySetInvoker(name); + } +} diff --git a/Cql/CqlSdkPrototype/Invocation.Fluent/Extensions/FluentInvocationToolkitExtensions.cs b/Cql/CqlSdkPrototype/Invocation.Fluent/Extensions/FluentInvocationToolkitExtensions.cs new file mode 100644 index 000000000..44e6c59c7 --- /dev/null +++ b/Cql/CqlSdkPrototype/Invocation.Fluent/Extensions/FluentInvocationToolkitExtensions.cs @@ -0,0 +1,13 @@ +using Hl7.Cql.CodeGeneration.NET; + +namespace CqlSdkPrototype.Invocation.Fluent.Extensions; + +public static class FluentInvocationToolkitExtensions +{ + public static FluentInvocationToolkit AddAssemblyBinaries( + this FluentInvocationToolkit invocationToolkit, + params AssemblyBinary[] assemblyBinary) + { + return invocationToolkit.AddAssemblyBinaries(assemblyBinary.AsEnumerable()); + } +} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Invocation.Fluent/FluentInvocationToolkit.cs b/Cql/CqlSdkPrototype/Invocation.Fluent/FluentInvocationToolkit.cs new file mode 100644 index 000000000..8816e39b1 --- /dev/null +++ b/Cql/CqlSdkPrototype/Invocation.Fluent/FluentInvocationToolkit.cs @@ -0,0 +1,59 @@ +using Hl7.Cql.CodeGeneration.NET; + +namespace CqlSdkPrototype.Invocation.Fluent; + +/// +/// Provides a fluent interface for building and configuring a . +/// +public sealed class FluentInvocationToolkit +{ + private readonly LibrarySetInvokerBuilder librarySetInvokerBuilder; + + /// + /// Initializes a new instance of the class with a default logger factory. + /// + public FluentInvocationToolkit() : this(default(ILoggerFactory)) { } + + /// + /// Initializes a new instance of the class with the specified logger factory. + /// + /// The logger factory to use for logging. + public FluentInvocationToolkit(ILoggerFactory? loggerFactory) + : this(new LibrarySetInvokerBuilder(loggerFactory)) + { } + + /// + /// Initializes a new instance of the class with the specified library set invoker builder. + /// + /// The library set invoker builder to use. + public FluentInvocationToolkit(LibrarySetInvokerBuilder librarySetInvokerBuilder) + { + this.librarySetInvokerBuilder = librarySetInvokerBuilder; + } + + /// + /// Gets the logger factory used by the exceptions. + /// + public ILoggerFactory LoggerFactory => librarySetInvokerBuilder.LoggerFactory; + + /// + /// Adds the specified assembly binaries to the toolkit. + /// + /// The assembly binaries to add. + /// The current instance of . + public FluentInvocationToolkit AddAssemblyBinaries(IEnumerable assemblyBinary) + { + librarySetInvokerBuilder.AddAssemblyBinaries(assemblyBinary); + return this; + } + + /// + /// Builds and returns a with the specified name. + /// + /// The name of the library set invoker. + /// A instance. + public LibrarySetInvoker ToLibrarySetInvoker(string name = "") + { + return librarySetInvokerBuilder.ToLibrarySetInvoker(name); + } +} diff --git a/Cql/CqlSdkPrototype/Invocation/DefinitionInvoker.cs b/Cql/CqlSdkPrototype/Invocation/DefinitionInvoker.cs new file mode 100644 index 000000000..cb070d35e --- /dev/null +++ b/Cql/CqlSdkPrototype/Invocation/DefinitionInvoker.cs @@ -0,0 +1,71 @@ +using Hl7.Cql.Abstractions; +using Hl7.Cql.Runtime; + +namespace CqlSdkPrototype.Invocation; + + +/// +/// Abstract class representing a definition invoker. +/// +/// The name of the definition. +/// The library containing the definition. +/// The method information for the definition. +/// The tag values associated with the definition. +/// The value set identifier, if any. +public abstract class DefinitionInvoker( + string definitionName, + ILibrary library, + MethodInfo methodInfo, + IReadOnlyDictionary tagValuesByName, + string? valueSetId) +{ + /// + /// Gets the name of the definition. + /// + public string DefinitionName { get; } = definitionName; + + /// + /// Gets the return type of the method. + /// + public Type ReturnType => MethodInfo.ReturnType; + + /// + /// Gets the tag values associated with the definition. + /// + public IReadOnlyDictionary TagValuesByName { get; } = tagValuesByName; + + /// + /// Gets the value set identifier, if any. + /// + public string? ValueSetId { get; } = valueSetId; + + /// + /// Gets the library containing the definition. + /// + private ILibrary Library { get; } = library; // Might decide to make this public later + + /// + /// Gets the method information for the definition. + /// + private MethodInfo MethodInfo { get; } = methodInfo; + + /// + /// Invokes the definition with the given CQL context. + /// + /// The CQL context. + /// The result of the invocation. + public abstract object? Invoke(CqlContext cqlContext); + + /// + /// Invokes the method with the specified parameters. + /// + /// The parameters to pass to the method. + /// The result of the method invocation. + protected object? InvokeMethod(params object?[] parameters) + { + MethodInfo methodInfo = MethodInfo; + ILibrary library = Library; + var result = methodInfo.Invoke(library, BindingFlags.DoNotWrapExceptions, null, parameters, CultureInfo.InvariantCulture); + return result; + } +} diff --git a/Cql/CqlSdkPrototype/Invocation/Extensions/LibraryInvokerExtensions.cs b/Cql/CqlSdkPrototype/Invocation/Extensions/LibraryInvokerExtensions.cs new file mode 100644 index 000000000..e850fd45e --- /dev/null +++ b/Cql/CqlSdkPrototype/Invocation/Extensions/LibraryInvokerExtensions.cs @@ -0,0 +1,25 @@ +using Hl7.Cql.Runtime; + +namespace CqlSdkPrototype.Invocation.Extensions; + +public static class LibraryInvokerExtensions +{ + public static IEnumerable<(DefinitionInvoker definitionInvoker, Func getResult)> EnumerateLibraryDefinitionsResults( + this LibraryInvoker libraryInvoker, + CqlContext cqlContext) + { + foreach (var definitionInvoker in libraryInvoker.Definitions.Values) + { + if (definitionInvoker.ValueSetId is not null) + continue; + + yield return (definitionInvoker, + () => + { + var result = definitionInvoker.Invoke(cqlContext); + return result; + } + ); + } + } +} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Invocation/Extensions/LibrarySetInvokerExtensions.cs b/Cql/CqlSdkPrototype/Invocation/Extensions/LibrarySetInvokerExtensions.cs new file mode 100644 index 000000000..1b8ae480a --- /dev/null +++ b/Cql/CqlSdkPrototype/Invocation/Extensions/LibrarySetInvokerExtensions.cs @@ -0,0 +1,39 @@ +using CqlSdkPrototype.Infrastructure; +using Hl7.Cql.Runtime; + +namespace CqlSdkPrototype.Invocation.Extensions; + +public static class LibrarySetInvokerExtensions +{ + public static IEnumerable<(LibraryInvoker libraryInvoker, DefinitionInvoker definitionInvoker, Func getResult)> EnumerateLibrarySetDefinitionsResults( + this LibrarySetInvoker librarySetInvoker, + CqlContext cqlContext) + { + foreach (var libraryInvoker in librarySetInvoker.LibraryInvokers.Values) + foreach (var (definition, getResult) in libraryInvoker.EnumerateLibraryDefinitionsResults(cqlContext)) + yield return (libraryInvoker, definition, getResult); + } + + public static IEnumerable<(LibraryInvoker libraryInvoker, DefinitionInvoker definitionInvoker, Func getResult)> EnumerateLibraryDefinitionsResults( + this LibrarySetInvoker librarySetInvoker, + CqlContext cqlContext, + CqlVersionedLibraryIdentifier cqlVersionedLibraryIdentifier) + { + var libraryInvoker = librarySetInvoker.LibraryInvokers[cqlVersionedLibraryIdentifier]; + foreach (var (definitionInvoker, getResult) in libraryInvoker.EnumerateLibraryDefinitionsResults(cqlContext)) + yield return (libraryInvoker, definitionInvoker, getResult); + } + + + public static object? GetLibraryDefinitionResult( + this LibrarySetInvoker librarySetInvoker, + CqlContext cqlContext, + CqlVersionedLibraryIdentifier cqlVersionedLibraryIdentifier, + string definitionName) + { + var libraryInvoker = librarySetInvoker.LibraryInvokers[cqlVersionedLibraryIdentifier]; + var libraryDeclarationInvoker = libraryInvoker.Definitions[definitionName]; + var result = libraryDeclarationInvoker.Invoke(cqlContext); + return result; + } +} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Runtime/Invokers/LibraryInvoker.2_0_8_0.cs b/Cql/CqlSdkPrototype/Invocation/Internal/LibraryInvoker.2_0_8_0.cs similarity index 77% rename from Cql/CqlSdkPrototype/Runtime/Invokers/LibraryInvoker.2_0_8_0.cs rename to Cql/CqlSdkPrototype/Invocation/Internal/LibraryInvoker.2_0_8_0.cs index 5f3406abf..2eb4823e0 100644 --- a/Cql/CqlSdkPrototype/Runtime/Invokers/LibraryInvoker.2_0_8_0.cs +++ b/Cql/CqlSdkPrototype/Invocation/Internal/LibraryInvoker.2_0_8_0.cs @@ -1,13 +1,12 @@ using System.Collections.ObjectModel; using CqlSdkPrototype.Internal; -using CqlSdkPrototype.Runtime.Extensibility; using Hl7.Cql.Abstractions; using Hl7.Cql.Abstractions.Infrastructure; using Hl7.Cql.Runtime; -namespace CqlSdkPrototype.Runtime.Invokers; +namespace CqlSdkPrototype.Invocation.Internal; -internal class LibraryInvoker_2_0_8_0 : LibraryInvokerOnInstance +internal sealed class LibraryInvoker_2_0_8_0 : LibraryInvokerOnInstance { private record LibraryMethodInfo( MethodInfo Method, @@ -26,7 +25,7 @@ public LibraryMethodInfo(MethodInfo Method) : this( DeclarationName: Method.GetCustomAttribute()?.Name) { } } - public LibraryInvoker_2_0_8_0( + private LibraryInvoker_2_0_8_0( ILibrary library) : base(library) { var libraryType = library.GetType(); @@ -37,12 +36,12 @@ public LibraryInvoker_2_0_8_0( .SelectWhereNotNull(o => o.DeclarationName is { } declarationName && o.Method.GetParameters() is [{ } p0] && p0.ParameterType == typeof(CqlContext) - ? (LibraryDefinitionInvoker)new DefinitionInvoker(declarationName, Library, o.Method, o.TagValuesByName, o.ValueSetId) + ? (Invocation.DefinitionInvoker)new DefinitionInvoker(declarationName, Library, o.Method, o.TagValuesByName, o.ValueSetId) : null) - .ToImmutableDictionary(o => o.DeclarationName); + .ToImmutableDictionary(o => o.DefinitionName); } - public override IReadOnlyDictionary Definitions { get; } + public override IReadOnlyDictionary Definitions { get; } private static object GetLibraryFromStaticInstanceProperty(Type libraryType) { @@ -50,13 +49,13 @@ private static object GetLibraryFromStaticInstanceProperty(Type libraryType) ?? throw new InvalidOperationException($"Unable to create an instance of {libraryType.FullName}"); } - public new static bool TryCreateFromType( - RuntimeApi runtimeApi, + public static bool TryCreate( + LibrarySetInvokerBuilder builder, Type libraryType, [NotNullWhen(true)] out LibraryInvoker? libraryInvoker) { libraryInvoker = null; - var logger = runtimeApi.AsExtendable().LoggerFactory.CreateLogger(); + var logger = builder.LoggerFactory.CreateLogger(); if (GetLibraryFromStaticInstanceProperty(libraryType) is not ILibrary asILibrary) { @@ -76,11 +75,11 @@ public static bool SupportsVersion(Version cqlToolVersion) } private class DefinitionInvoker( - string declarationName, + string definitionName, ILibrary library, MethodInfo methodInfo, IReadOnlyDictionary tagValuesByName, - string? valueSetId) : LibraryDefinitionInvoker(declarationName, library, methodInfo, tagValuesByName, valueSetId) + string? valueSetId) : Invocation.DefinitionInvoker(definitionName, library, methodInfo, tagValuesByName, valueSetId) { public override object? Invoke(CqlContext cqlContext) { diff --git a/Cql/CqlSdkPrototype/Invocation/Internal/LibrarySetInvokerBuilderServices.cs b/Cql/CqlSdkPrototype/Invocation/Internal/LibrarySetInvokerBuilderServices.cs new file mode 100644 index 000000000..0f504df40 --- /dev/null +++ b/Cql/CqlSdkPrototype/Invocation/Internal/LibrarySetInvokerBuilderServices.cs @@ -0,0 +1,12 @@ +namespace CqlSdkPrototype.Invocation.Internal; + +internal readonly record struct LibrarySetInvokerBuilderServices( + ILogger Logger) +{ + public static LibrarySetInvokerBuilderServices Create( + ILoggerFactory loggerFactory) + { + // No other services needed at this time. + return new LibrarySetInvokerBuilderServices(loggerFactory.CreateLogger()); + } +} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Runtime/Invokers/LibraryInvoker.cs b/Cql/CqlSdkPrototype/Invocation/LibraryInvoker.cs similarity index 57% rename from Cql/CqlSdkPrototype/Runtime/Invokers/LibraryInvoker.cs rename to Cql/CqlSdkPrototype/Invocation/LibraryInvoker.cs index 8ee43912e..a7f813b97 100644 --- a/Cql/CqlSdkPrototype/Runtime/Invokers/LibraryInvoker.cs +++ b/Cql/CqlSdkPrototype/Invocation/LibraryInvoker.cs @@ -1,27 +1,40 @@ using System.CodeDom.Compiler; using CqlSdkPrototype.Infrastructure; -using CqlSdkPrototype.Runtime.Extensibility; +using CqlSdkPrototype.Invocation.Internal; using Hl7.Cql.Abstractions; -namespace CqlSdkPrototype.Runtime.Invokers; +namespace CqlSdkPrototype.Invocation; /// -/// Represents an invoker for a CQL library. +/// Abstract base class for invoking CQL libraries. /// public abstract class LibraryInvoker { + /// + /// Gets the versioned identifier of the CQL library. + /// public abstract CqlVersionedLibraryIdentifier LibraryVersionedIdentifier { get; } - public abstract IReadOnlyDictionary Definitions { get; } + /// + /// Gets the dictionary of definition invokers for the CQL library. + /// + public abstract IReadOnlyDictionary Definitions { get; } + /// + /// Tries to create a instance from the specified type. + /// + /// The builder for the library set invoker. + /// The type of the library. + /// When this method returns, contains the created instance, if the creation succeeded; otherwise, . + /// if the creation succeeded; otherwise, . public static bool TryCreateFromType( - RuntimeApi runtimeApi, + LibrarySetInvokerBuilder librarySetInvokerBuilder, Type libraryType, [NotNullWhen(true)] out LibraryInvoker? libraryInvoker) { libraryInvoker = null; - var logger = runtimeApi.AsExtendable().LoggerFactory.CreateLogger(); + var logger = librarySetInvokerBuilder.LoggerFactory.CreateLogger(); if (libraryType.GetCustomAttribute() is not { }) { @@ -48,7 +61,7 @@ public static bool TryCreateFromType( if (LibraryInvoker_2_0_8_0.SupportsVersion(cqlToolVersion)) { - if (LibraryInvoker_2_0_8_0.TryCreateFromType(runtimeApi, libraryType, out libraryInvoker)) + if (LibraryInvoker_2_0_8_0.TryCreate(librarySetInvokerBuilder, libraryType, out libraryInvoker)) return true; } @@ -59,4 +72,4 @@ public static bool TryCreateFromType( return false; } -} \ No newline at end of file +} diff --git a/Cql/CqlSdkPrototype/Runtime/Invokers/LibraryInvokerOnInstance.cs b/Cql/CqlSdkPrototype/Invocation/LibraryInvokerOnInstance.cs similarity index 91% rename from Cql/CqlSdkPrototype/Runtime/Invokers/LibraryInvokerOnInstance.cs rename to Cql/CqlSdkPrototype/Invocation/LibraryInvokerOnInstance.cs index 54ba0ea93..e8a09f8e0 100644 --- a/Cql/CqlSdkPrototype/Runtime/Invokers/LibraryInvokerOnInstance.cs +++ b/Cql/CqlSdkPrototype/Invocation/LibraryInvokerOnInstance.cs @@ -1,7 +1,7 @@ using CqlSdkPrototype.Infrastructure; using Hl7.Cql.Abstractions; -namespace CqlSdkPrototype.Runtime.Invokers; +namespace CqlSdkPrototype.Invocation; public abstract class LibraryInvokerOnInstance(ILibrary library) : LibraryInvoker { diff --git a/Cql/CqlSdkPrototype/Invocation/LibrarySetInvoker.cs b/Cql/CqlSdkPrototype/Invocation/LibrarySetInvoker.cs new file mode 100644 index 000000000..584da212c --- /dev/null +++ b/Cql/CqlSdkPrototype/Invocation/LibrarySetInvoker.cs @@ -0,0 +1,45 @@ +using CqlSdkPrototype.Infrastructure; +using CqlSdkPrototype.Internal; + +namespace CqlSdkPrototype.Invocation; + + +/// +/// Represents an invoker for a set of CQL libraries. +/// +public sealed class LibrarySetInvoker : IDisposable +{ + private readonly AssemblyLoadContext _alc; + + /// + /// Initializes a new instance of the class. + /// + /// The builder used to create the library set invoker. + /// The assembly load context. + internal LibrarySetInvoker(LibrarySetInvokerBuilder librarySetInvokerBuilder, AssemblyLoadContext alc) + { + _alc = alc; + LibraryInvokers = + _alc.Assemblies + .SelectMany(a => a.GetTypes()) + .SelectWhereNotNull(t => + { + LibraryInvoker.TryCreateFromType(librarySetInvokerBuilder, t, out var libraryInvoker); + return libraryInvoker; + }) + .ToImmutableDictionary(o => o.LibraryVersionedIdentifier); + } + + /// + /// Releases all resources used by the . + /// + public void Dispose() + { + _alc.Unload(); + } + + /// + /// Gets the dictionary of library invokers. + /// + public IReadOnlyDictionary LibraryInvokers { get; } +} diff --git a/Cql/CqlSdkPrototype/Invocation/LibrarySetInvokerBuilder.cs b/Cql/CqlSdkPrototype/Invocation/LibrarySetInvokerBuilder.cs new file mode 100644 index 000000000..0edb0cb5b --- /dev/null +++ b/Cql/CqlSdkPrototype/Invocation/LibrarySetInvokerBuilder.cs @@ -0,0 +1,91 @@ +using CqlSdkPrototype.Internal; +using CqlSdkPrototype.Invocation.Fluent; +using CqlSdkPrototype.Invocation.Internal; +using Hl7.Cql.Abstractions.Infrastructure; +using Hl7.Cql.CodeGeneration.NET; + +namespace CqlSdkPrototype.Invocation; + + +/// +/// Builder class for creating instances of . +/// +public sealed class LibrarySetInvokerBuilder +{ + /// + /// Initializes a new instance of the class. + /// + /// Optional logger factory for logging purposes. + public LibrarySetInvokerBuilder( + ILoggerFactory? loggerFactory = null/*, + LibrarySetInvokerBuilderConfig? config = null*/) + { + /*config ??= LibrarySetInvokerBuilderConfig.Default;*/ + loggerFactory ??= NullLoggerFactory.Instance; + LoggerFactory = loggerFactory; + AssemblyBinaries = AssemblyBinaryHashSet.Empty; + /*Config = config;*/ + _services = LibrarySetInvokerBuilderServices.Create(loggerFactory); + } + + /// + /// Gets the logger factory used by extensions on the . + /// + internal ILoggerFactory LoggerFactory { get; } + + /// + /// Gets the set of assembly binaries. + /// + public AssemblyBinaryHashSet AssemblyBinaries { get; private set; } + + /*public LibrarySetInvokerBuilderConfig Config { get; private set; }*/ + + private LibrarySetInvokerBuilderServices _services; + + /// + /// Sets the assembly binaries. + /// + /// The assembly binaries to set. + private void SetAssemblyBinaries( + AssemblyBinaryHashSet assemblyBinaries) + { + AssemblyBinaries = assemblyBinaries; + } + + /*public void Reconfigure( + LibrarySetInvokerBuilderConfig config) + { + // No need to recreate services here yet + Config = config; + }*/ + + /// + /// Adds assembly binaries to the current set. + /// + /// The assembly binaries to add. + /// Thrown when AssemblyBytes is null. + public void AddAssemblyBinaries(IEnumerable assemblyBinary) + { + _services.Logger.LogInformation("Adding assemblies"); + var builder = AssemblyBinaries.ToBuilder(); + var oldCount = builder.Count; + var addEntries = assemblyBinary.Select(ad => new AssemblyBinary(ad.AssemblyBytes ?? throw new InvalidOperationException("AssemblyBytes must not be null"), ad.DebugSymbolsBytes)); + builder.AddRange(addEntries); + if (oldCount != builder.Count) + SetAssemblyBinaries(builder.ToImmutable()); + } + + /// + /// Creates a new instance of . + /// + /// The name of the AssemblyLoadContext. + /// A new instance of . + public LibrarySetInvoker ToLibrarySetInvoker(string name = "") + { + _services.Logger.LogDebug("Creating LibrarySetInvoker"); + var alc = new AssemblyLoadContext(name, true); + foreach (var (assembly, debugSymbols) in AssemblyBinaries) + alc.LoadFromBytes(assembly!, debugSymbols); + return new LibrarySetInvoker(this, alc); + } +} diff --git a/Cql/CqlSdkPrototype/Logging/ColorConsoleLogger.cs b/Cql/CqlSdkPrototype/Logging/ColorConsoleLogger.cs index 4e43aa3d9..da5b51546 100644 --- a/Cql/CqlSdkPrototype/Logging/ColorConsoleLogger.cs +++ b/Cql/CqlSdkPrototype/Logging/ColorConsoleLogger.cs @@ -2,6 +2,11 @@ namespace CqlSdkPrototype.Logging; +/// +/// This class is not part of the API. It is used internally by the prototype and the PackagerCLI. +/// It will be moved to the PackagerCLI once the prototype is complete, +/// and then it will move to the PackagerCLI and made internal. +/// public sealed partial class ColorConsoleLogger(string categoryName, ColorConsoleLoggerProvider provider) : ILogger { private readonly string _categoryName = categoryName.Length == 0 ? "" : $"{categoryName}: "; diff --git a/Cql/CqlSdkPrototype/Logging/ColorConsoleLoggerProvider.cs b/Cql/CqlSdkPrototype/Logging/ColorConsoleLoggerProvider.cs index 72e7596e9..1ea90be66 100644 --- a/Cql/CqlSdkPrototype/Logging/ColorConsoleLoggerProvider.cs +++ b/Cql/CqlSdkPrototype/Logging/ColorConsoleLoggerProvider.cs @@ -1,5 +1,10 @@ namespace CqlSdkPrototype.Logging; +/// +/// This class is not part of the API. It is used internally by the prototype and the PackagerCLI. +/// It will be moved to the PackagerCLI once the prototype is complete, +/// and then it will move to the PackagerCLI and made internal. +/// public sealed class ColorConsoleLoggerProvider : ILoggerProvider { private readonly Func _updateCategoryName; diff --git a/Cql/CqlSdkPrototype/Program.cs b/Cql/CqlSdkPrototype/Program.cs deleted file mode 100644 index 7a792e8d0..000000000 --- a/Cql/CqlSdkPrototype/Program.cs +++ /dev/null @@ -1,221 +0,0 @@ -using CqlSdkPrototype.Cql; -using CqlSdkPrototype.Cql.Extensibility; -using CqlSdkPrototype.Cql.Extensions; -using CqlSdkPrototype.Elm.Extensibility; -using CqlSdkPrototype.Elm.Extensions; -using CqlSdkPrototype.Infrastructure; -using CqlSdkPrototype.Internal; -using CqlSdkPrototype.Logging; -using CqlSdkPrototype.Runtime.Extensions; -using Hl7.Cql.CodeGeneration.NET; -using Hl7.Cql.Fhir; -using Hl7.Cql.Runtime.Hosting; -using static Hl7.Cql.Abstractions.Exceptions.ProcessBatchItemExceptionHandling; - -namespace CqlSdkPrototype; - -internal class Program -{ - static void Main(string[] args) - { - using var serviceProvider = - new ServiceCollection() - .AddLogging(lb => lb - .ClearProviders() - .AddProvider(new ColorConsoleLoggerProvider()) - .AddFilter((category, _) => category?.Contains(value: nameof(CqlSdkPrototype)) ?? false)) - .BuildServiceProvider(); - - var loggerFactory = serviceProvider.GetRequiredService(); - var cqlApiOptions = new CqlApiOptions(Models: [CqlModel.ElmR1, CqlModel.Fhir401]); - var cqlApi = new CqlApi(loggerFactory, cqlApiOptions); - - var logger = serviceProvider.GetLogger(); - - //InvokeCqlExample(cqlApi: cqlApi); - - //InvokeCqlFromExamplesFolder(logger: logger, cqlApi: cqlApi); - // - foreach (var librarySetName in (string[]) ["CMS"])//"Authoring", "CMS", "Demo", "Examples"]) - VerboseExample(logger: logger, cqlApi: cqlApi, librarySetName: librarySetName, shouldBuildCqlToElm:false); - - // VerboseExample(logger, cqlApi, "CMS"); - } - - private static void InvokeCqlFromExamplesFolder( - ILogger logger, - CqlApi cqlApi) - { - // INTRO: - // This example demonstrates how to load CQL libraries from a directory and invoke a library declarations directly. - - // "Directories" is not a part of the API, but a helper class for this example - var dirs = Directories.Create("Examples"); - - // We can write extensions to make it even easier to change exception handling - var cqlContext = FhirCqlContext.ForBundle(); - - // We need a disposable invocation scope, which contains the AssemblyLoadContext and the related library Assemblies. - using var invocationScope = cqlApi - .WithOptions(o => o with { ProcessBatchItemExceptionHandling = IgnoreExceptionAndContinue }) - .AddCqlLibrariesFromDirectory(dirs.CqlInDirectory) - .CreateRuntimeScope(); - logger.LogInformation("{dump}", invocationScope.DumpLibraryDeclarations()); - Debug.Assert(Invoke("CqlAggregateFunctionsTest-1.0.000", "Count.CountTestTime") is 3); - Debug.Assert(Invoke("CqlAggregateFunctionsTest-1.0.000", "Count.CountTestNull") is 0); - Debug.Assert(Invoke("CqlStringOperatorsTest-1.0.000", "Combine.CombineABCSepDash") is "a-b-c"); - - object? Invoke(string libraryName, string declarationName) - { - var libraryIdentifier = CqlVersionedLibraryIdentifier.Parse(libraryName); - var result = invocationScope.GetLibraryDefinitionResult(cqlContext, libraryIdentifier, declarationName); - return result; - } - } - - private static void InvokeCqlExample(CqlApi cqlApi) - { - // INTRO: - // This example demonstrates how to add a CqlLibraryString to the CqlApi and invoke a library declaration directly. - - // NICE TO HAVE: Would be nice to parse the CqlLibraryString only from the CQL and extract the identifier from the CQL - var cqlLibraryString = CqlLibraryString.Parse( - """ - library AdditionLib version '0.0.0' - - define private Three: 1 + 2 - """); - var cqlContext = FhirCqlContext.ForBundle(); - using var invocationScope = cqlApi - .AddCqlLibraryString(cqlLibraryString) - .CreateRuntimeScope(elmOpt => elmOpt with { AssemblyCompilerDebugInformationFormat = AssemblyCompilerDebugInformationFormat.Embedded }); - var result = invocationScope.GetLibraryDefinitionResult(cqlContext, cqlLibraryString.VersionedLibraryIdentifier, "Three"); - Debug.Assert(result is 3); - } - - private static void VerboseExample( - ILogger logger, - CqlApi cqlApi, - string librarySetName, - bool shouldBuildCqlToElm = false) - { - // INTRO: - // This example loads the CQL libraries, translates them to ELM, and compiles them to assemblies. - // Each intermediate format is saved to directory (e.g. ELM, C#, and assembly binaries with their debug symbols). - // It also demonstrates how to execute a library. - - Directories dirs = Directories.Create(librarySetName); - dirs.GeneratedDirectory.Delete(recursive: true); - - cqlApi.WithOptions(o => o with { ProcessBatchItemExceptionHandling = IgnoreExceptionAndContinue }); - - if (shouldBuildCqlToElm) - { - cqlApi - .AddCqlLibrariesFromDirectory( - dirs.CqlInDirectory /*, - options: new EnumerationOptions() - { - //RecurseSubdirectories = false - }*/ /*, - filePredicate: fi => fi.Name.TrimFileExtension(".cql") is - "FHIRHelpers" - or "NCQATerminology" - or "NCQAStatus"*/ - ) - .Translate() - .SaveElmFileToDirectory(dirs.ElmOutDirectory) - ; - } - - var elmApi = cqlApi.CreateElmApi(o => o with { AssemblyCompilerDebugInformationFormat = AssemblyCompilerDebugInformationFormat.Embedded }) - .AddElmFilesFromDirectory(dirs.ElmInDirectory) - .Compile() - .SaveCSharpFilesToDirectory(dirs.CSharpOutDirectory) - .SaveAssemblyBinariesToDirectory(dirs.AssembliesOutDirectory); - - cqlApi.TryGetFirstElmFileLines() - .Switch(t => logger.LogInformation( - $""" - First 50 ELM lines for {t.id}: - {t.elmJson.TakeLines(50)} - """)); - - elmApi.TryGetFirstCSharpFileLines() - .Switch(t => logger.LogInformation( - $""" - First 50 C# lines for {t.id}: - {t.cSharpSourceCode.TakeLines(50)} - """)); - } - - // private static void ExecuteLibrary( - // ServiceProvider serviceProvider, - // Directories dirs, - // CqlApi cqlTranslation, - // ElmApi elmCompilation, - // FhirJsonPocoDeserializer fhirJsonPocoDeserializer) - // { - // var logger = serviceProvider.GetLogger(); - // if (RuntimeApi.Create( - // out var librarySetInvoker)) - // { - // // logger.LogInformation("{msg}", sb.ToString()); - // // - // // if (dirs.ValueSetsInDirectory is null) - // // { - // // logger.LogWarning("No value sets directory found. Skipping execution."); - // // return; - // // } - // - // /*dirs.ValueSetsInDirectory.EnumerateFiles("*.json", SearchOption.AllDirectories) - // .Select(fi => - // { - // using var stream = fi.OpenRead(); - // var reader = new Utf8JsonReader(); - // return fhirJsonPocoDeserializer.DeserializeObject(reader); - // });*/ - // - // Bundle? bundle = new Bundle(){}; - // Dictionary? parameters = new() - // { - // ["Measurement Period"] = new CqlInterval( - // low: new CqlDate(2023, 1, 1), - // high: new CqlDate(2023, 12, 31), - // lowClosed: true, - // highClosed: true) - // }; - // - // IValueSetDictionary? valueSets = null; - // FhirCqlContextOptions? options = null; - // CqlContext cqlContext = FhirCqlContext - // //.WithDataSource(source, parameters, valueSets, options: options); - // .ForBundle(bundle, parameters, valueSets, options:options); - // var parametersExample = librarySetInvoker.LibraryInvokers[CqlVersionedLibraryIdentifier.Parse("ParametersExample-0.0.1")]; - // var patientDeclaration = parametersExample.Declarations["Patient"]; - // var patient = patientDeclaration.Invoke(cqlContext); - // } - // } -} - -file static class X -{ - public static Maybe<(CqlVersionedLibraryIdentifier id, string cSharpSourceCode)> - TryGetFirstCSharpFileLines( - this TElmApi elmApi) - where TElmApi : IElmApiExtendable - { - return elmApi.Entries - .TryGetFirst(kv => kv.Value.CSharpSourceCode is not null) - .TryReturn(kv => (kv.Key, kv.Value.CSharpSourceCode!)); - } - - public static Maybe<(CqlVersionedLibraryIdentifier id, string elmJson)> TryGetFirstElmFileLines( - this TCqlApi cqlApi) - where TCqlApi : ICqlApiExtendable - { - return cqlApi.Entries - .TryGetFirst(kv => kv.Value.ElmLibrary is not null) - .TryReturn(kv => (kv.Key, kv.Value.ElmLibrary!.SerializeToJson()!)); - } -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Runtime/Extensibility/IRuntimeApiExtendable.cs b/Cql/CqlSdkPrototype/Runtime/Extensibility/IRuntimeApiExtendable.cs deleted file mode 100644 index d68e3108f..000000000 --- a/Cql/CqlSdkPrototype/Runtime/Extensibility/IRuntimeApiExtendable.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Hl7.Cql.CodeGeneration.NET; - -namespace CqlSdkPrototype.Runtime.Extensibility; - -public interface IRuntimeApiExtendable - where TRuntimeApi : IRuntimeApiExtendable -{ - ILoggerFactory LoggerFactory { get; } - RuntimeApiOptions Options { get; } - IReadOnlySet Entries { get; } - TRuntimeApi WithOptions(Func replaceOptions); - TRuntimeApi AddAssemblies(IEnumerable assemblies); -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Runtime/Extensibility/RuntimeApiExtendableExtensions.cs b/Cql/CqlSdkPrototype/Runtime/Extensibility/RuntimeApiExtendableExtensions.cs deleted file mode 100644 index fe47aee96..000000000 --- a/Cql/CqlSdkPrototype/Runtime/Extensibility/RuntimeApiExtendableExtensions.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace CqlSdkPrototype.Runtime.Extensibility; - -public static class RuntimeApiExtendableExtensions -{ - public static IRuntimeApiExtendable AsExtendable(this RuntimeApi self) => self; -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Runtime/Extensibility/RuntimeApiStateEntry.cs b/Cql/CqlSdkPrototype/Runtime/Extensibility/RuntimeApiStateEntry.cs deleted file mode 100644 index 2a639448f..000000000 --- a/Cql/CqlSdkPrototype/Runtime/Extensibility/RuntimeApiStateEntry.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace CqlSdkPrototype.Runtime.Extensibility; - -public readonly record struct RuntimeApiStateEntry(byte[] AssemblyBytes, byte[]? DebugSymbolsBytes = null); \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Runtime/Extensions/RuntimeApiExtensions.Cql.cs b/Cql/CqlSdkPrototype/Runtime/Extensions/RuntimeApiExtensions.Cql.cs deleted file mode 100644 index 2cbaaa7b5..000000000 --- a/Cql/CqlSdkPrototype/Runtime/Extensions/RuntimeApiExtensions.Cql.cs +++ /dev/null @@ -1,33 +0,0 @@ -using CqlSdkPrototype.Cql; -using CqlSdkPrototype.Cql.Extensibility; -using CqlSdkPrototype.Elm; -using CqlSdkPrototype.Elm.Extensions; - -namespace CqlSdkPrototype.Runtime.Extensions; - -public static partial class RuntimeApiExtensions -{ - public static ElmApi CreateElmApi( - this TCqlApi cqlApi, - Func? configureOptions = null) - where TCqlApi : ICqlApiExtendable - { - var elmApiOptions = new ElmApiOptions(ProcessBatchItemExceptionHandling: cqlApi.Options.ProcessBatchItemExceptionHandling); - if (configureOptions is not null) elmApiOptions = configureOptions(elmApiOptions); - var elmApi = new ElmApi(cqlApi.LoggerFactory, elmApiOptions).AddElmFromCqlApi(cqlApi); - return elmApi; - } - -#pragma warning disable RS0026 - public static RuntimeScope CreateRuntimeScope( -#pragma warning restore RS0026 - this CqlApi cqlApi, - Func? configureElmOptions = null, - Func? configureRuntimeOptions = null) - { - return cqlApi - .Translate() - .CreateElmApi(configureElmOptions) - .CreateRuntimeScope(configureRuntimeOptions); - } -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Runtime/Extensions/RuntimeApiExtensions.Elm.cs b/Cql/CqlSdkPrototype/Runtime/Extensions/RuntimeApiExtensions.Elm.cs deleted file mode 100644 index ade8a37e4..000000000 --- a/Cql/CqlSdkPrototype/Runtime/Extensions/RuntimeApiExtensions.Elm.cs +++ /dev/null @@ -1,40 +0,0 @@ -using CqlSdkPrototype.Elm.Extensibility; -using Hl7.Cql.CodeGeneration.NET; - -namespace CqlSdkPrototype.Runtime.Extensions; - -public static partial class RuntimeApiExtensions -{ - public static RuntimeApi CreateRuntimeApi( - this TElmApi elmApi, - Func? configureOptions = null) - where TElmApi : IElmApiExtendable - { - var runtimeApiOptions = RuntimeApiOptions.Default; - if (configureOptions is not null) runtimeApiOptions = configureOptions(runtimeApiOptions); - - var assemblyDatas = - from entry in elmApi.Entries - let assembly = entry.Value.AssemblyBinary - where assembly is not null - let debugSymbols = entry.Value.DebugSymbolsBinary - let assemblyData = new AssemblyData(assembly, debugSymbols) - select assemblyData; - - var runtimeApi = new RuntimeApi(elmApi.LoggerFactory, runtimeApiOptions).AddAssemblies(assemblyDatas); - return runtimeApi; - } - -#pragma warning disable RS0026 - public static RuntimeScope CreateRuntimeScope( -#pragma warning restore RS0026 - this TElmApi elmApi, - Func? configureOptions = null) - where TElmApi : IElmApiExtendable - { - return elmApi - .Compile() - .CreateRuntimeApi(configureOptions) - .CreateRuntimeScope(); - } -} diff --git a/Cql/CqlSdkPrototype/Runtime/Extensions/RuntimeApiExtensions.RuntimeScope.cs b/Cql/CqlSdkPrototype/Runtime/Extensions/RuntimeApiExtensions.RuntimeScope.cs deleted file mode 100644 index 8cbe0ccb2..000000000 --- a/Cql/CqlSdkPrototype/Runtime/Extensions/RuntimeApiExtensions.RuntimeScope.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System.Text; -using CqlSdkPrototype.Infrastructure; -using Hl7.Cql.Abstractions.Infrastructure; -using Hl7.Cql.Runtime; -using static System.FormattableString; - -namespace CqlSdkPrototype.Runtime.Extensions; - -public static partial class RuntimeApiExtensions -{ - public static IEnumerable<(CqlVersionedLibraryIdentifier library, string declarationName, Func getResult)> EnumerateLibrarySetDefinitionsResults( - this RuntimeScope scope, - CqlContext cqlContext) - { - foreach (var (libId, lib) in scope.Libraries) - { - foreach (var (declId, decl) in lib.Definitions) - { - if (decl.ValueSetId is not null) - continue; - - yield return (libId, declId, () => - { - var result = decl.Invoke(cqlContext); - return result; - } - ); - } - } - } - - public static IEnumerable<(string definition, Func getResult)> EnumerateLibraryDefinitionsResults( - this RuntimeScope scope, - CqlContext cqlContext, - CqlVersionedLibraryIdentifier library) - { - var lib = scope.Libraries[library]; - foreach (var (declId, decl) in lib.Definitions) - { - if (decl.ValueSetId is not null) - continue; - - yield return (declId, () => - { - var result = decl.Invoke(cqlContext); - return result; - } - ); - } - } - - public static object? GetLibraryDefinitionResult( - this RuntimeScope scope, - CqlContext cqlContext, - CqlVersionedLibraryIdentifier versionedLibraryIdentifier, - string definitionName) - { - var libraryInvoker = scope.Libraries[versionedLibraryIdentifier]; - var libraryDeclarationInvoker = libraryInvoker.Definitions[definitionName]; - var result = libraryDeclarationInvoker.Invoke(cqlContext); - return result; - } - - internal static StringBuilder DumpLibraryDeclarations( - this RuntimeScope scope, - StringBuilder? sb = null) - { - sb ??= new(); - sb.AppendLine("Libraries and Declarations:"); - foreach (var (libId, lib) in scope.Libraries) - { - sb.AppendLine(Invariant($"- {libId}")); - foreach (var (declId, decl) in lib.Definitions) - sb.AppendLine(Invariant($" - {declId} : {decl.ReturnType.ToCSharpString(TypeCSharpFormat.Default with { UseKeywords = true })}")); - } - - return sb; - } -} diff --git a/Cql/CqlSdkPrototype/Runtime/Extensions/RuntimeApiExtensions.cs b/Cql/CqlSdkPrototype/Runtime/Extensions/RuntimeApiExtensions.cs deleted file mode 100644 index dcf04cf29..000000000 --- a/Cql/CqlSdkPrototype/Runtime/Extensions/RuntimeApiExtensions.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace CqlSdkPrototype.Runtime.Extensions; - -public static partial class RuntimeApiExtensions -{ - // This file is intentionally left blank - since it's the parent file for nested RuntimeApiExtensions.* files -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Runtime/Internal/ElmApiInternalExtensions.cs b/Cql/CqlSdkPrototype/Runtime/Internal/ElmApiInternalExtensions.cs deleted file mode 100644 index 24ede699c..000000000 --- a/Cql/CqlSdkPrototype/Runtime/Internal/ElmApiInternalExtensions.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace CqlSdkPrototype.Runtime.Internal; - -internal static class RuntimeApiInternalExtensions -{ - internal static IRuntimeApiInternal AsInternal(this IRuntimeApiInternal self) - where TRuntimeApi : IRuntimeApiInternal => self; -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Runtime/Internal/IElmApiInternal.cs b/Cql/CqlSdkPrototype/Runtime/Internal/IElmApiInternal.cs deleted file mode 100644 index bb737b15a..000000000 --- a/Cql/CqlSdkPrototype/Runtime/Internal/IElmApiInternal.cs +++ /dev/null @@ -1,9 +0,0 @@ -using CqlSdkPrototype.Runtime.Extensibility; - -namespace CqlSdkPrototype.Runtime.Internal; - -internal interface IRuntimeApiInternal : IRuntimeApiExtendable - where TRuntimeApi : IRuntimeApiExtendable -{ - RuntimeApiState State { get; } -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Runtime/Invokers/LibraryDefinitionInvoker.cs b/Cql/CqlSdkPrototype/Runtime/Invokers/LibraryDefinitionInvoker.cs deleted file mode 100644 index ee1519a7f..000000000 --- a/Cql/CqlSdkPrototype/Runtime/Invokers/LibraryDefinitionInvoker.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Hl7.Cql.Abstractions; -using Hl7.Cql.Runtime; - -namespace CqlSdkPrototype.Runtime.Invokers; - -public abstract class LibraryDefinitionInvoker( - string declarationName, - ILibrary library, - MethodInfo methodInfo, - IReadOnlyDictionary tagValuesByName, - string? valueSetId) -{ - public string DeclarationName { get; } = declarationName; - public Type ReturnType => MethodInfo.ReturnType; - public IReadOnlyDictionary TagValuesByName { get; } = tagValuesByName; - public string? ValueSetId { get; } = valueSetId; - private ILibrary Library { get; } = library; // Might decide to make this public later - private MethodInfo MethodInfo { get; } = methodInfo; - public abstract object? Invoke(CqlContext cqlContext); - - protected object? InvokeMethod(params object?[] parameters) - { - MethodInfo methodInfo = MethodInfo; - ILibrary library = Library; - var result = methodInfo.Invoke(library, BindingFlags.DoNotWrapExceptions, null, parameters, CultureInfo.InvariantCulture); - return result; - } -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Runtime/RuntimeApi.cs b/Cql/CqlSdkPrototype/Runtime/RuntimeApi.cs deleted file mode 100644 index 642e81a92..000000000 --- a/Cql/CqlSdkPrototype/Runtime/RuntimeApi.cs +++ /dev/null @@ -1,71 +0,0 @@ -using CqlSdkPrototype.Internal; -using Hl7.Cql.Abstractions.Infrastructure; -using Hl7.Cql.CodeGeneration.NET; -using CqlSdkPrototype.Runtime.Extensibility; - -namespace CqlSdkPrototype.Runtime; - -public class RuntimeApi : IRuntimeApiExtendable -{ - public RuntimeApi( - ILoggerFactory? loggerFactory = null, - RuntimeApiOptions? options = null) - : this (RuntimeApiState.Create(loggerFactory ?? NullLoggerFactory.Instance, options ?? RuntimeApiOptions.Default)) - { } - - internal RuntimeApi(RuntimeApiState state) => _state = state; // Might make this public later. Used for testing now. - - #region State - - private RuntimeApiState _state; - - private RuntimeApi WithEntries( - ImmutableHashSet? assemblyData = null) - { - _state = _state with - { - Entries = assemblyData ?? _state.Entries - }; - return this; - } - - public RuntimeApi WithOptions( - Func replaceOptions) - { - var newOptions = replaceOptions(_state.Options); - if (!ReferenceEquals(_state.Options, newOptions)) - _state = _state with { Options = newOptions }; - return this; - } - - RuntimeApiOptions IRuntimeApiExtendable.Options => _state.Options; - IReadOnlySet IRuntimeApiExtendable.Entries => _state.Entries; - ILoggerFactory IRuntimeApiExtendable.LoggerFactory => _state.LoggerFactory; - - #endregion - - #region Input (AssemblyData's) - - public RuntimeApi AddAssemblies(IEnumerable assemblyData) - { - var assembliesBuilder = _state.Entries.ToBuilder(); - var oldCount = assembliesBuilder.Count; - var addEntries = assemblyData.Select(ad => new RuntimeApiStateEntry(ad.AssemblyBytes ?? throw new InvalidOperationException("AssemblyBytes must not be null"), ad.DebugSymbolsBytes)); - assembliesBuilder.AddRange(addEntries); - return oldCount == assembliesBuilder.Count ? this : WithEntries(assemblyData: assembliesBuilder.ToImmutable()); - } - - #endregion - - #region Output (InvocationScope) - - public RuntimeScope CreateRuntimeScope() - { - var alc = new AssemblyLoadContext("", true); - foreach (var (assembly, debugSymbols) in _state.Entries) - alc.LoadFromBytes(assembly!, debugSymbols); - return new RuntimeScope(this, alc); - } - - #endregion -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Runtime/RuntimeApiOptions.cs b/Cql/CqlSdkPrototype/Runtime/RuntimeApiOptions.cs deleted file mode 100644 index e6fd849c3..000000000 --- a/Cql/CqlSdkPrototype/Runtime/RuntimeApiOptions.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace CqlSdkPrototype.Runtime; - -public record RuntimeApiOptions() -{ - public static RuntimeApiOptions Default { get; } = new(); -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Runtime/RuntimeApiState.cs b/Cql/CqlSdkPrototype/Runtime/RuntimeApiState.cs deleted file mode 100644 index cd84f5a6a..000000000 --- a/Cql/CqlSdkPrototype/Runtime/RuntimeApiState.cs +++ /dev/null @@ -1,36 +0,0 @@ -using CqlSdkPrototype.Runtime.Extensibility; - -namespace CqlSdkPrototype.Runtime; - -internal readonly record struct RuntimeApiState( - ILoggerFactory LoggerFactory, - ImmutableHashSet Entries, - RuntimeApiOptions Options, - ILogger Logger) -{ - public static RuntimeApiState Create(ILoggerFactory loggerFactory, RuntimeApiOptions options) - { - return new RuntimeApiState(loggerFactory, [], null!, null!) - { - // Must be set through the property initializer, to ensure the services are created - Options = options, - }; - } - - private readonly RuntimeApiOptions _options = Options; - - public RuntimeApiOptions Options - { - get => _options; - init - { - if (ReferenceEquals(_options, value)) - return; - - _options = value; - Logger = LoggerFactory.CreateLogger(); - } - } - - public ILoggerFactory LoggerFactory { get; } = LoggerFactory; -} \ No newline at end of file diff --git a/Cql/CqlSdkPrototype/Runtime/RuntimeScope.cs b/Cql/CqlSdkPrototype/Runtime/RuntimeScope.cs deleted file mode 100644 index ee3f7f2d5..000000000 --- a/Cql/CqlSdkPrototype/Runtime/RuntimeScope.cs +++ /dev/null @@ -1,31 +0,0 @@ -using CqlSdkPrototype.Infrastructure; -using CqlSdkPrototype.Internal; -using CqlSdkPrototype.Runtime.Invokers; - -namespace CqlSdkPrototype.Runtime; - -public class RuntimeScope : IDisposable -{ - private readonly AssemblyLoadContext _alc; - - internal RuntimeScope(RuntimeApi runtimeApi, AssemblyLoadContext alc) - { - _alc = alc; - Libraries = - _alc.Assemblies - .SelectMany(a => a.GetTypes()) - .SelectWhereNotNull(t => - { - LibraryInvoker.TryCreateFromType(runtimeApi, t, out var libraryInvoker); - return libraryInvoker; - }) - .ToImmutableDictionary(o => o.LibraryVersionedIdentifier); - } - - public void Dispose() - { - _alc.Unload(); - } - - public IReadOnlyDictionary Libraries { get; } -} \ No newline at end of file diff --git a/Cql/CqlToElmTests/AdditionTest.cs b/Cql/CqlToElmTests/(tests)/AdditionTest.cs similarity index 95% rename from Cql/CqlToElmTests/AdditionTest.cs rename to Cql/CqlToElmTests/(tests)/AdditionTest.cs index 2f408cad7..5f5d4df3c 100644 --- a/Cql/CqlToElmTests/AdditionTest.cs +++ b/Cql/CqlToElmTests/(tests)/AdditionTest.cs @@ -15,7 +15,7 @@ public class AdditionTest : Base [TestMethod] public void Add_Integer_to_Integer() { - var library = CreateCqlApi().MakeLibrary( + var library = CreateFluentCqlToolkit().MakeLibrary( """ library Add_Integer_to_Integer version '1.0.0' @@ -63,7 +63,7 @@ library Add_Integer_to_Integer version '1.0.0' Assert.AreEqual("2", rhs.value); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(int?)); @@ -74,7 +74,7 @@ library Add_Integer_to_Integer version '1.0.0' [TestMethod] public void Add_Long_to_Long() { - var library = CreateCqlApi().MakeLibrary( + var library = CreateFluentCqlToolkit().MakeLibrary( """ library Add_Long_to_Long version '1.0.0' @@ -122,7 +122,7 @@ library Add_Long_to_Long version '1.0.0' Assert.AreEqual("2", rhs.value); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -133,7 +133,7 @@ library Add_Long_to_Long version '1.0.0' [TestMethod] public void Add_Decimal_to_Decimal() { - var library = CreateCqlApi().MakeLibrary( + var library = CreateFluentCqlToolkit().MakeLibrary( """ library Add_Decimal_to_Decimal version '1.0.0' @@ -181,7 +181,7 @@ library Add_Decimal_to_Decimal version '1.0.0' Assert.AreEqual("2.0", rhs.value); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -192,7 +192,7 @@ library Add_Decimal_to_Decimal version '1.0.0' [TestMethod] public void Add_Quantity_to_Quantity() { - var library = CreateCqlApi().MakeLibrary( + var library = CreateFluentCqlToolkit().MakeLibrary( """ library Add_Decimal_to_Quantity version '1.0.0' @@ -242,7 +242,7 @@ library Add_Decimal_to_Quantity version '1.0.0' Assert.AreEqual(UCUMUnits.Default, rhs.unit); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -260,7 +260,7 @@ library Add_Decimal_to_Quantity version '1.0.0' [TestMethod] public void Add_Integer_to_Long() { - var library = CreateCqlApi().MakeLibrary( + var library = CreateFluentCqlToolkit().MakeLibrary( """ library Add_Integer_to_Long version '1.0.0' @@ -307,7 +307,7 @@ library Add_Integer_to_Long version '1.0.0' Assert.AreEqual("2", rhs.value); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -318,7 +318,7 @@ library Add_Integer_to_Long version '1.0.0' [TestMethod] public void Add_Integer_to_Decimal() { - var library = CreateCqlApi().MakeLibrary( + var library = CreateFluentCqlToolkit().MakeLibrary( """ library Add_Integer_to_Decimal version '1.0.0' @@ -365,7 +365,7 @@ library Add_Integer_to_Decimal version '1.0.0' Assert.AreEqual("2.0", rhs.value); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -376,7 +376,7 @@ library Add_Integer_to_Decimal version '1.0.0' [TestMethod] public void Add_Integer_to_Quantity() { - var library = CreateCqlApi().MakeLibrary( + var library = CreateFluentCqlToolkit().MakeLibrary( """ library Add_Integer_to_Quantity version '1.0.0' @@ -424,7 +424,7 @@ library Add_Integer_to_Quantity version '1.0.0' Assert.AreEqual(UCUMUnits.Default, rhs.unit); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -438,7 +438,7 @@ library Add_Integer_to_Quantity version '1.0.0' [TestMethod] public void Add_Long_to_Decimal() { - var library = CreateCqlApi().MakeLibrary( + var library = CreateFluentCqlToolkit().MakeLibrary( """ library Add_Long_to_Decimal version '1.0.0' @@ -485,7 +485,7 @@ library Add_Long_to_Decimal version '1.0.0' Assert.AreEqual("2.0", rhs.value); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -496,7 +496,7 @@ library Add_Long_to_Decimal version '1.0.0' [TestMethod] public void Add_Long_to_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Integer_to_Quantity version '1.0.0' define private Three: 1L + 2.0 '1' @@ -543,7 +543,7 @@ library Add_Integer_to_Quantity version '1.0.0' Assert.AreEqual(UCUMUnits.Default, rhs.unit); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -557,7 +557,7 @@ library Add_Integer_to_Quantity version '1.0.0' [TestMethod] public void Add_Decimal_to_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Decimal_to_Quantity version '1.0.0' define private Three: -1.0 + 2.0 '1' @@ -604,7 +604,7 @@ library Add_Decimal_to_Quantity version '1.0.0' Assert.AreEqual(UCUMUnits.Default, rhs.unit); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -622,7 +622,7 @@ library Add_Decimal_to_Quantity version '1.0.0' [TestMethod] public void Add_Long_to_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Long_to_Integer version '1.0.0' define private Three: 1L + 2 @@ -667,7 +667,7 @@ library Add_Long_to_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -678,7 +678,7 @@ library Add_Long_to_Integer version '1.0.0' [TestMethod] public void Add_Decimal_to_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Decimal_to_Integer version '1.0.0' define private Three: 5.25 + 2 @@ -723,7 +723,7 @@ library Add_Decimal_to_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -734,7 +734,7 @@ library Add_Decimal_to_Integer version '1.0.0' [TestMethod] public void Add_Quantity_to_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Decimal_to_Integer version '1.0.0' define private Three: 5.25 '1' + 2 @@ -779,7 +779,7 @@ library Add_Decimal_to_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -793,7 +793,7 @@ library Add_Decimal_to_Integer version '1.0.0' [TestMethod] public void Add_Decimal_to_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Decimal_to_Long version '1.0.0' define private Three: 5.25 + 2L @@ -838,7 +838,7 @@ library Add_Decimal_to_Long version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -849,7 +849,7 @@ library Add_Decimal_to_Long version '1.0.0' [TestMethod] public void Add_Quantity_to_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Quantity_to_Long version '1.0.0' define private Three: 5.25 '1' + 2L @@ -894,7 +894,7 @@ library Add_Quantity_to_Long version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -908,7 +908,7 @@ library Add_Quantity_to_Long version '1.0.0' [TestMethod] public void Add_Quantity_to_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Quantity_to_Decimal version '1.0.0' define private Three: 5.25 '1' + 2.0 @@ -953,7 +953,7 @@ library Add_Quantity_to_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -971,7 +971,7 @@ library Add_Quantity_to_Decimal version '1.0.0' [TestMethod] public void Add_Null_to_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Null_to_Integer version '1.0.0' define private AddNull: null + 1 @@ -1016,7 +1016,7 @@ library Add_Null_to_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -1026,7 +1026,7 @@ library Add_Null_to_Integer version '1.0.0' [TestMethod] public void Add_Integer_to_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Null_to_Integer version '1.0.0' define private AddNull: 1 + null @@ -1070,7 +1070,7 @@ library Add_Null_to_Integer version '1.0.0' Assert.IsNotNull(lhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Integer", lhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -1084,7 +1084,7 @@ library Add_Null_to_Integer version '1.0.0' [TestMethod] public void Add_Quantity_to_Date() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Quantity_to_Date version '1.0.0' define private Three: @2023-01-01 + 1 month @@ -1129,7 +1129,7 @@ library Add_Quantity_to_Date version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -1144,7 +1144,7 @@ library Add_Quantity_to_Date version '1.0.0' [TestMethod] public void Add_Null_to_Date() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Quantity_to_Date version '1.0.0' define private Three: @2023-01-01 + null @@ -1189,7 +1189,7 @@ library Add_Quantity_to_Date version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -1199,7 +1199,7 @@ library Add_Quantity_to_Date version '1.0.0' [TestMethod] public void Add_Quantity_to_DateTime() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Quantity_to_DateTime version '1.0.0' define private Three: @2023-01-01T01:23:45.300+01:30 + 1 month @@ -1244,7 +1244,7 @@ library Add_Quantity_to_DateTime version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -1265,7 +1265,7 @@ library Add_Quantity_to_DateTime version '1.0.0' [TestMethod] public void Add_Null_to_DateTime() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Null_To_DateTime version '1.0.0' define private Three: @2023-01-01T01:23:45.300+01:30 + null @@ -1310,7 +1310,7 @@ library Add_Null_To_DateTime version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -1320,7 +1320,7 @@ library Add_Null_To_DateTime version '1.0.0' [TestMethod] public void Add_Quantity_to_Time() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DefaultConverter version '1.0.0' define private Three: @T01:23:45 + 1 hour @@ -1365,7 +1365,7 @@ library DefaultConverter version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -1381,7 +1381,7 @@ library DefaultConverter version '1.0.0' [TestMethod] public void Add_Null_to_Time() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Null_To_DateTime version '1.0.0' define private Three: @T01:23:45 + null @@ -1426,7 +1426,7 @@ library Add_Null_To_DateTime version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -1436,21 +1436,21 @@ library Add_Null_To_DateTime version '1.0.0' [TestMethod] public void Add_DateTypes_to_Quantity() { - CreateCqlApi() + CreateFluentCqlToolkit() .MakeLibrary(""" library Add_Date_to_Quantity version '1.0.0' define private Test: 1 month + @2023-01-01 """, "Could not resolve call to operator Add*"); - CreateCqlApi() + CreateFluentCqlToolkit() .MakeLibrary(""" library Add_Time_to_Quantity version '1.0.0' define private Test: 1 month + @T01:23:45 """, "Could not resolve call to operator Add*"); - CreateCqlApi() + CreateFluentCqlToolkit() .MakeLibrary(""" library Add_DateTime_to_Quantity version '1.0.0' @@ -1463,7 +1463,7 @@ library Add_DateTime_to_Quantity version '1.0.0' [TestMethod] public void Add_Three_Decimals() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Decimal_to_Decimal version '1.0.0' define private Three: 1.0 + (2.0 + 3.0) @@ -1508,7 +1508,7 @@ library Add_Decimal_to_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -1519,7 +1519,7 @@ library Add_Decimal_to_Decimal version '1.0.0' [TestMethod] public void Add_Quantity_to_Two_Decimals() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Decimal_to_Decimal version '1.0.0' define private Three: 1.0 '1' + (2.0 + 3.0) @@ -1564,7 +1564,7 @@ library Add_Decimal_to_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -1578,7 +1578,7 @@ library Add_Decimal_to_Decimal version '1.0.0' [TestMethod] public void Add_Strings_With_Plus() { - var library = CreateCqlApi().MakeLibraryFromExpression("'hello' + 'world'"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("'hello' + 'world'"); library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); } } diff --git a/Cql/CqlToElmTests/AgeTest.cs b/Cql/CqlToElmTests/(tests)/AgeTest.cs similarity index 97% rename from Cql/CqlToElmTests/AgeTest.cs rename to Cql/CqlToElmTests/(tests)/AgeTest.cs index cf6765cb8..5555c6ca8 100644 --- a/Cql/CqlToElmTests/AgeTest.cs +++ b/Cql/CqlToElmTests/(tests)/AgeTest.cs @@ -8,7 +8,7 @@ public class AgeTest : Base { private void TestCalculateAgeAt(string type, DateTimePrecision unit) { - var lib = CreateCqlApi().MakeLibrary($""" + var lib = CreateFluentCqlToolkit().MakeLibrary($""" library AgeTest version '1.0.0' using FHIR version '4.0.1' @@ -23,7 +23,7 @@ define function CalculateAgeAt(birthDate {type}, at {type}): private void TestAgeAt(string type, DateTimePrecision unit) { - var lib = CreateCqlApi().MakeLibrary($""" + var lib = CreateFluentCqlToolkit().MakeLibrary($""" library AgeTest version '1.0.0' using FHIR version '4.0.1' @@ -38,7 +38,7 @@ define function AgeAt(at {type}): private void TestCalculateAge(string type, DateTimePrecision unit) { - var lib = CreateCqlApi().MakeLibrary($""" + var lib = CreateFluentCqlToolkit().MakeLibrary($""" library AgeTest version '1.0.0' using FHIR version '4.0.1' @@ -53,7 +53,7 @@ define function CalculateAge(birthDate {type}): private void TestAge(string type, DateTimePrecision unit) { - var lib = CreateCqlApi().MakeLibrary($""" + var lib = CreateFluentCqlToolkit().MakeLibrary($""" library AgeTest version '1.0.0' using FHIR version '4.0.1' diff --git a/Cql/CqlToElmTests/AndTest.cs b/Cql/CqlToElmTests/(tests)/AndTest.cs similarity index 95% rename from Cql/CqlToElmTests/AndTest.cs rename to Cql/CqlToElmTests/(tests)/AndTest.cs index da65ff237..9d8da4375 100644 --- a/Cql/CqlToElmTests/AndTest.cs +++ b/Cql/CqlToElmTests/(tests)/AndTest.cs @@ -9,7 +9,7 @@ public class AndTest : Base [TestMethod] public void True_And_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library AndTest version '1.0.0' define private True_And_False: true and false @@ -54,7 +54,7 @@ library AndTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(and); + var lambda = ToFluentElmToolkit().Lambda(and); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -65,7 +65,7 @@ library AndTest version '1.0.0' [TestMethod] public void True_And_True() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library AndTest version '1.0.0' define private True_And_True: true and true @@ -110,7 +110,7 @@ library AndTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(and); + var lambda = ToFluentElmToolkit().Lambda(and); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -121,7 +121,7 @@ library AndTest version '1.0.0' [TestMethod] public void False_And_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library AndTest version '1.0.0' define private False_And_False: false and false @@ -166,7 +166,7 @@ library AndTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(and); + var lambda = ToFluentElmToolkit().Lambda(and); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -177,7 +177,7 @@ library AndTest version '1.0.0' [TestMethod] public void True_And_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library AndTest version '1.0.0' define private True_And_Null: true and null @@ -222,7 +222,7 @@ library AndTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(and); + var lambda = ToFluentElmToolkit().Lambda(and); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -232,7 +232,7 @@ library AndTest version '1.0.0' [TestMethod] public void Null_And_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library AndTest version '1.0.0' define private Null_And_False: null and false @@ -277,7 +277,7 @@ library AndTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(and); + var lambda = ToFluentElmToolkit().Lambda(and); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -288,7 +288,7 @@ library AndTest version '1.0.0' [TestMethod] public void Null_And_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library AndTest version '1.0.0' define private Null_And_Null: null and null @@ -333,7 +333,7 @@ library AndTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(and); + var lambda = ToFluentElmToolkit().Lambda(and); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -343,7 +343,7 @@ library AndTest version '1.0.0' [TestMethod] public void True_And_1() { - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library AndTest version '1.0.0' define private True_And_1: true and 1 diff --git a/Cql/CqlToElmTests/AsTest.cs b/Cql/CqlToElmTests/(tests)/AsTest.cs similarity index 87% rename from Cql/CqlToElmTests/AsTest.cs rename to Cql/CqlToElmTests/(tests)/AsTest.cs index a0a100d9b..d76bac1e9 100644 --- a/Cql/CqlToElmTests/AsTest.cs +++ b/Cql/CqlToElmTests/(tests)/AsTest.cs @@ -10,7 +10,7 @@ public class AsTest : Base [TestMethod] public void Integer_As_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library AsTest version '1.0.0' define private Integer_As_Decimal: 1 as System.Decimal @@ -21,7 +21,7 @@ library AsTest version '1.0.0' [TestMethod] public void ValueSet_As_Vocabulary() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library AsTest version '1.0.0' valueset "vs": 'http://xyz.com' @@ -41,7 +41,7 @@ library AsTest version '1.0.0' var nts = (NamedTypeSpecifier)@as.asTypeSpecifier; Assert.AreEqual($"{{{SystemUri}}}Vocabulary", nts.name?.Name); - var delegates = CreateElmApi().ProcessLibrary(library).CompileAll(); + var delegates = ToFluentElmToolkit().ProcessLibrary(library).CompileAll(); var dg = delegates["AsTest-1.0.0", "ValueSet_As_Vocabulary"]; var ctx = FhirCqlContext.ForBundle(delegates: delegates); var result = dg.DynamicInvoke(ctx); @@ -53,7 +53,7 @@ library AsTest version '1.0.0' [TestMethod] public void Null_As_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library AsTest version '1.0.0' define private Null_As_Decimal: null as System.Decimal @@ -95,7 +95,7 @@ private static As AssertAsTypes(Library library, string literalTypeName, string private void AssertAsNull(As @as) { - var lambda = CreateElmApi().Lambda(@as); + var lambda = ToFluentElmToolkit().Lambda(@as); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); @@ -105,7 +105,7 @@ private void AssertAsNull(As @as) [TestMethod] public void DecimalLiteral_CastAs_Decimal() { - var library = CreateCqlApi().MakeLibraryFromExpression("cast (1.0 as System.Any) as System.Decimal"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("cast (1.0 as System.Any) as System.Decimal"); var castAs = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); castAs.strict.Should().BeTrue(); @@ -116,7 +116,7 @@ public void DecimalLiteral_CastAs_Decimal() [TestMethod] public void BooleanLiteral_CastAs_Decimal() { - var library = CreateCqlApi().MakeLibraryFromExpression("cast (true as System.Any) as System.Decimal"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("cast (true as System.Any) as System.Decimal"); var castAs = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); castAs.strict.Should().BeTrue(); @@ -127,7 +127,7 @@ public void BooleanLiteral_CastAs_Decimal() [TestMethod] public void FhirId_As_FhirString() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library AsTest version '1.0.0' using FHIR version '4.0.1' @@ -135,7 +135,7 @@ library AsTest version '1.0.0' define private function f(id FHIR.id): id as FHIR.string """); lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); - var lambdas = CreateElmApi().ProcessLibrary(lib); + var lambdas = ToFluentElmToolkit().ProcessLibrary(lib); var delegates = lambdas.CompileAll(); var dg = delegates[lib.GetVersionedIdentifier(), "f", typeof(Hl7.Fhir.Model.Id)]; var ctx = FhirCqlContext.ForBundle(); @@ -148,7 +148,7 @@ define private function f(id FHIR.id): id as FHIR.string public void Choice_As() { // from MATGlobalCommonFunctionsFHIR4.cql function "Normalize Interval" - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library AsTest version '1.0.0' using FHIR version '4.0.1' @@ -159,7 +159,7 @@ context Patient define private function f(choice Choice): choice as FHIR.Range """); - _ = CreateElmApi().ProcessLibrary(lib); + _ = ToFluentElmToolkit().ProcessLibrary(lib); } } } diff --git a/Cql/CqlToElmTests/BetweenTest.cs b/Cql/CqlToElmTests/(tests)/BetweenTest.cs similarity index 83% rename from Cql/CqlToElmTests/BetweenTest.cs rename to Cql/CqlToElmTests/(tests)/BetweenTest.cs index 3fb48ee06..2b124cbab 100644 --- a/Cql/CqlToElmTests/BetweenTest.cs +++ b/Cql/CqlToElmTests/(tests)/BetweenTest.cs @@ -8,7 +8,7 @@ public class BetweenTest : Base [TestMethod] public void BetweenIntTrue() { - var lib = CreateCqlApi().MakeLibraryFromExpression("4 between 2 and 6"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("4 between 2 and 6"); var and = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); and.operand.Should().HaveCount(2); var ge = and.operand[0].Should().BeOfType().Subject; @@ -20,7 +20,7 @@ public void BetweenIntTrue() [TestMethod] public void ProperBetweenIntFalse() { - var lib = CreateCqlApi().MakeLibraryFromExpression("2 properly between 2 and 6"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("2 properly between 2 and 6"); var and = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); and.operand.Should().HaveCount(2); var ge = and.operand[0].Should().BeOfType().Subject; diff --git a/Cql/CqlToElmTests/BooleanTest.cs b/Cql/CqlToElmTests/(tests)/BooleanTest.cs similarity index 78% rename from Cql/CqlToElmTests/BooleanTest.cs rename to Cql/CqlToElmTests/(tests)/BooleanTest.cs index 4821898b4..9d6dfd0ea 100644 --- a/Cql/CqlToElmTests/BooleanTest.cs +++ b/Cql/CqlToElmTests/(tests)/BooleanTest.cs @@ -9,7 +9,7 @@ public class BooleanTest : Base [TestMethod] public void True_Is_True() { - var library = CreateCqlApi().MakeLibraryFromExpression("true is true"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("true is true"); var isTrue = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); isTrue.operand.Should().BeLiteralBool(true); AssertResult(isTrue, true); @@ -18,7 +18,7 @@ public void True_Is_True() [TestMethod] public void True_Is_False() { - var library = CreateCqlApi().MakeLibraryFromExpression("true is false"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("true is false"); var isFalse = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); isFalse.operand.Should().BeLiteralBool(true); AssertResult(isFalse, false); @@ -27,7 +27,7 @@ public void True_Is_False() [TestMethod] public void True_Is_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("true is null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("true is null"); var isNull = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var @as = isNull.operand.Should().BeOfType().Subject; @as.Should().HaveType(SystemTypes.AnyType); @@ -38,7 +38,7 @@ public void True_Is_Null() [TestMethod] public void Null_Is_True() { - var library = CreateCqlApi().MakeLibraryFromExpression("null is true"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null is true"); var isTrue = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var @as = isTrue.operand.Should().BeOfType().Subject; @as.operand.Should().BeNullLiteral(); @@ -48,7 +48,7 @@ public void Null_Is_True() [TestMethod] public void Null_Is_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("null is null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null is null"); var isNull = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); isNull.operand.Should().BeNullLiteral(); AssertResult(isNull, true); @@ -57,7 +57,7 @@ public void Null_Is_Null() [TestMethod] public void True_Is_Not_False() { - var library = CreateCqlApi().MakeLibraryFromExpression("true is not false"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("true is not false"); var isNot = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var isFalse = isNot.operand.Should().BeOfType().Subject; isFalse.operand.Should().BeLiteralBool(true); @@ -67,7 +67,7 @@ public void True_Is_Not_False() [TestMethod] public void True_Is_Not_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("true is not null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("true is not null"); var isNot = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var isNull = isNot.operand.Should().BeOfType().Subject; AssertResult(isNot, true); @@ -76,7 +76,7 @@ public void True_Is_Not_Null() [TestMethod] public void Null_Is_Not_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("null is not null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null is not null"); var isNot = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var isNull = isNot.operand.Should().BeOfType().Subject; isNull.operand.Should().BeNullLiteral(); @@ -86,7 +86,7 @@ public void Null_Is_Not_Null() [TestMethod] public void Null_Is_Not_False() { - var library = CreateCqlApi().MakeLibraryFromExpression("null is not false"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null is not false"); var isNot = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var isFalse = isNot.operand.Should().BeOfType().Subject; var @as = isFalse.operand.Should().BeOfType().Subject; @@ -97,7 +97,7 @@ public void Null_Is_Not_False() [TestMethod] public void TrueList_Is_True() { - var library = CreateCqlApi(EnableListDemotion:true ).MakeLibraryFromExpression("{true} is true"); + var library = CreateFluentCqlToolkit(EnableListDemotion:true ).MakeLibraryFromExpression("{true} is true"); var isTrue = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var singleton = isTrue.operand.Should().BeOfType().Subject; singleton.resultTypeSpecifier.Should().Be(SystemTypes.BooleanType); diff --git a/Cql/CqlToElmTests/CaseTest.cs b/Cql/CqlToElmTests/(tests)/CaseTest.cs similarity index 98% rename from Cql/CqlToElmTests/CaseTest.cs rename to Cql/CqlToElmTests/(tests)/CaseTest.cs index b07c6e494..ab294f6ec 100644 --- a/Cql/CqlToElmTests/CaseTest.cs +++ b/Cql/CqlToElmTests/(tests)/CaseTest.cs @@ -7,7 +7,7 @@ public class CaseTest : Base { private Library createLibraryForExpression(string expression) { - return CreateCqlApi().MakeLibrary($""" + return CreateFluentCqlToolkit().MakeLibrary($""" library CaseTest version '1.0.0' define private predicate: {expression} diff --git a/Cql/CqlToElmTests/CoercionTest.cs b/Cql/CqlToElmTests/(tests)/CoercionTest.cs similarity index 89% rename from Cql/CqlToElmTests/CoercionTest.cs rename to Cql/CqlToElmTests/(tests)/CoercionTest.cs index 860e05505..ed85bdf78 100644 --- a/Cql/CqlToElmTests/CoercionTest.cs +++ b/Cql/CqlToElmTests/(tests)/CoercionTest.cs @@ -1,5 +1,4 @@ using Hl7.Cql.Elm; -using CqlSdkPrototype.Cql.Internal; namespace Hl7.Cql.CqlToElm.Test { @@ -9,27 +8,42 @@ namespace Hl7.Cql.CqlToElm.Test [TestClass] public class CoercionTest : Base { - private static CoercionProvider CoercionProvider => CreateCqlApi( - EnableListPromotion:true, - EnableListDemotion:true, - EnableIntervalPromotion:true, - EnableIntervalDemotion:true).AsInternal().Services.ServiceProvider.GetRequiredService(); + static CoercionTest() + { + var fluentCqlToolkit = CreateFluentCqlToolkit( + EnableListPromotion: true, + EnableListDemotion: true, + EnableIntervalPromotion: true, + EnableIntervalDemotion: true); + ElmFactory = fluentCqlToolkit.GetElmFactory(); + CoercionProvider = fluentCqlToolkit.GetCoercionProvider(); + } + + private static readonly CoercionProvider CoercionProvider; - private static ElmFactory ElmFactory => CreateCqlApi().AsInternal().Services.ServiceProvider.GetRequiredService(); + private static readonly ElmFactory ElmFactory; private static Null Null() => new Null().WithResultType(SystemTypes.AnyType); private static Null Null(TypeSpecifier type) => new Null().WithResultType(type); private static Literal String(string value = "") => ElmFactory.Literal(value); - private static Literal Integer(int value = 1) => ElmFactory.Literal(value); private static Interval Interval(Expression low, Expression high) => new Interval { low = low, high = high }.WithResultType(low.resultTypeSpecifier.ToIntervalType()); + private static Literal Integer(int value = 1) => ElmFactory.Literal(value); + + private static Interval Interval(Expression low, Expression high) => + new Interval { low = low, high = high }.WithResultType(low.resultTypeSpecifier.ToIntervalType()); + + private static ValueSetRef ValueSet(string url = "http://hl7.org") => + new ValueSetRef { name = "TestValueSet" }.WithResultType(SystemTypes.ValueSetType); + + private static List List(TypeSpecifier elementType, params Expression[] elements) => + new List { element = elements }.WithResultType(elementType.ToListType()); - private static ValueSetRef ValueSet(string url = "http://hl7.org") => new ValueSetRef { name = "TestValueSet" }.WithResultType(SystemTypes.ValueSetType); - private static List List(TypeSpecifier elementType, params Expression[] elements) => new List { element = elements }.WithResultType(elementType.ToListType()); private static ChoiceTypeSpecifier Choice(params TypeSpecifier[] types) => new ChoiceTypeSpecifier(types); private static Tuple Tuple(params (string name, Expression value)[] tuple) => new Tuple { element = tuple.Select(t => new TupleElement { name = t.name, value = t.value }).ToArray() } - .WithResultType(TupleType(tuple.Select(t => (t.name, t.value.resultTypeSpecifier)).ToArray())); + .WithResultType(TupleType(tuple.Select(t => (t.name, t.value.resultTypeSpecifier)).ToArray())); + private static TypeSpecifier TupleType(params (string name, TypeSpecifier type)[] tuple) => new TupleTypeSpecifier { element = tuple.Select(t => new TupleElementDefinition { name = t.name, elementType = t.type }).ToArray() }; @@ -179,6 +193,7 @@ public void IntervalCanBeDemoted() Assert.IsTrue(result.Success); Assert.AreEqual(CoercionCost.IntervalDemotion, result.Cost); } + [TestMethod] public void ListCanBeDemoted() { @@ -187,6 +202,7 @@ public void ListCanBeDemoted() Assert.IsTrue(result.Success); Assert.AreEqual(CoercionCost.ListDemotion, result.Cost); } + [TestMethod] public void IntegerPromotedToDecimal() { @@ -196,6 +212,7 @@ public void IntegerPromotedToDecimal() Assert.IsInstanceOfType(result.Result, typeof(ToDecimal)); Assert.AreEqual(CoercionCost.ImplicitToSimpleType, result.Cost); } + [TestMethod] public void ListAnyCanBeCastToListInteger() { @@ -204,6 +221,7 @@ public void ListAnyCanBeCastToListInteger() Assert.IsTrue(result.Success); Assert.AreEqual(CoercionCost.MoreCompatible, result.Cost); } + [TestMethod] public void ListIsSubtypeOfAny() { @@ -216,20 +234,20 @@ public void ListIsSubtypeOfAny() [TestMethod] public void IntegerCanBeCastAsInteger() => CoercionProvider.CanBeCast(SystemTypes.IntegerType, SystemTypes.IntegerType) - .Should().BeTrue(); + .Should().BeTrue(); [TestMethod] public void AnyCanBeCastAsIntervalAny() => CoercionProvider.CanBeCast(SystemTypes.AnyType, SystemTypes.AnyType.ToIntervalType()) - .Should().BeTrue(); + .Should().BeTrue(); [TestMethod] public void ListIntervalIntegerToListIntervalDecimal() { var expression = List(SystemTypes.IntegerType.ToIntervalType(), - Interval(Integer(1), Integer(2))); + Interval(Integer(1), Integer(2))); var result = CoercionProvider.Coerce(expression, - SystemTypes.DecimalType.ToIntervalType().ToListType()); + SystemTypes.DecimalType.ToIntervalType().ToListType()); result.Success.Should().BeTrue(); result.Cost.Should().Be(CoercionCost.ImplicitToSimpleType); result.Result.Should().BeOfType(); @@ -241,7 +259,7 @@ public void IntervalIntegerToIntervalDecimal() { var expression = Interval(Integer(1), Integer(2)); var result = CoercionProvider.Coerce(expression, - SystemTypes.DecimalType.ToIntervalType()); + SystemTypes.DecimalType.ToIntervalType()); Assert.IsTrue(result.Success); Assert.AreEqual(CoercionCost.ImplicitToSimpleType, result.Cost); } @@ -251,7 +269,7 @@ public void ValueSetToListCode() { var expression = ValueSet(); var result = CoercionProvider.Coerce(expression, - SystemTypes.CodeType.ToListType()); + SystemTypes.CodeType.ToListType()); Assert.IsTrue(result.Success); Assert.AreEqual(CoercionCost.ImplicitToClassType, result.Cost); } @@ -301,6 +319,5 @@ public void FhirDateToSystemDate() Assert.IsInstanceOfType(fr.operand![0], typeof(Null)); Assert.AreEqual(SystemTypes.DateType, fr.resultTypeSpecifier); } - } -} +} \ No newline at end of file diff --git a/Cql/CqlToElmTests/ComponentFromTest.cs b/Cql/CqlToElmTests/(tests)/ComponentFromTest.cs similarity index 73% rename from Cql/CqlToElmTests/ComponentFromTest.cs rename to Cql/CqlToElmTests/(tests)/ComponentFromTest.cs index 05f9bab67..fb77baefe 100644 --- a/Cql/CqlToElmTests/ComponentFromTest.cs +++ b/Cql/CqlToElmTests/(tests)/ComponentFromTest.cs @@ -9,7 +9,7 @@ public class ComponentFromTest : Base [TestMethod] public void YearFromDateTime() { - var lib = CreateCqlApi().MakeLibraryFromExpression("year from DateTime(2003, 10, 29, 20, 50, 33, 955)"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("year from DateTime(2003, 10, 29, 20, 50, 33, 955)"); var cf = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(cf, lib); Assert.AreEqual(2003, result); @@ -17,7 +17,7 @@ public void YearFromDateTime() [TestMethod] public void YearFromDate() { - var lib = CreateCqlApi().MakeLibraryFromExpression("year from Date(2003, 10, 29)"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("year from Date(2003, 10, 29)"); var cf = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(cf, lib); Assert.AreEqual(2003, result); @@ -25,7 +25,7 @@ public void YearFromDate() [TestMethod] public void HourFromTime() { - var lib = CreateCqlApi().MakeLibraryFromExpression("hour from Time(20, 40, 20, 123)"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("hour from Time(20, 40, 20, 123)"); var cf = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(cf, lib); Assert.AreEqual(20, result); @@ -34,7 +34,7 @@ public void HourFromTime() [TestMethod] public void TimezoneOffsetFromDateTime() { - var lib = CreateCqlApi().MakeLibraryFromExpression("timezoneoffset from DateTime(2003, 10, 29, 20, 50, 33, 955, 5.5)"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("timezoneoffset from DateTime(2003, 10, 29, 20, 50, 33, 955, 5.5)"); var cf = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(cf, lib); Assert.AreEqual(5.5m, result); @@ -42,7 +42,7 @@ public void TimezoneOffsetFromDateTime() [TestMethod] public void DateFromDateTime() { - var lib = CreateCqlApi().MakeLibraryFromExpression("date from DateTime(2003, 10, 29, 20, 50, 33, 955, 5.5)"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("date from DateTime(2003, 10, 29, 20, 50, 33, 955, 5.5)"); var cf = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(cf, lib); Assert.IsNotNull(result); diff --git a/Cql/CqlToElmTests/ConcatenationTest.cs b/Cql/CqlToElmTests/(tests)/ConcatenationTest.cs similarity index 95% rename from Cql/CqlToElmTests/ConcatenationTest.cs rename to Cql/CqlToElmTests/(tests)/ConcatenationTest.cs index 59588ca78..5c80f259d 100644 --- a/Cql/CqlToElmTests/ConcatenationTest.cs +++ b/Cql/CqlToElmTests/(tests)/ConcatenationTest.cs @@ -10,7 +10,7 @@ public class ConcatenationTest : Base [TestMethod] public void Add_String_To_String() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Integer_to_Integer version '1.0.0' define private Three: 'hello' & 'world' @@ -57,7 +57,7 @@ library Add_Integer_to_Integer version '1.0.0' Assert.AreEqual("world", rhs.value); } - var lambda = CreateElmApi().Lambda(concatenate); + var lambda = ToFluentElmToolkit().Lambda(concatenate); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(string)); @@ -71,7 +71,7 @@ library Add_Integer_to_Integer version '1.0.0' [TestMethod] public void Add_Three_Strings() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Add_Integer_to_Integer version '1.0.0' define private Three: 'hello' & (' ' & 'world') @@ -116,7 +116,7 @@ library Add_Integer_to_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}String", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(concatenate); + var lambda = ToFluentElmToolkit().Lambda(concatenate); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(string)); diff --git a/Cql/CqlToElmTests/ConcurrentWithTest.cs b/Cql/CqlToElmTests/(tests)/ConcurrentWithTest.cs similarity index 95% rename from Cql/CqlToElmTests/ConcurrentWithTest.cs rename to Cql/CqlToElmTests/(tests)/ConcurrentWithTest.cs index 95dfd212e..c1756f030 100644 --- a/Cql/CqlToElmTests/ConcurrentWithTest.cs +++ b/Cql/CqlToElmTests/(tests)/ConcurrentWithTest.cs @@ -17,7 +17,7 @@ public class ConcurrentWithTest : Base [TestMethod] public void Starts_Days_Or_Before_Start() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Starts_Days_Or_Before_Start: Interval[@2023-01-01, @2023-03-31] starts same day or before start Interval[@2023-04-01, @2023-04-30] @@ -45,7 +45,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Starts_Days_Or_Before_End() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Starts_Days_Or_Before_End: Interval[@2023-01-01, @2023-03-31] starts same day or before end Interval[@2023-04-01, @2023-04-30] @@ -73,7 +73,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Starts_Days_Or_After_Start() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Starts_Days_Or_After_Start: Interval[@2023-01-01, @2023-03-31] starts same day or after start Interval[@2023-04-01, @2023-04-30] @@ -101,7 +101,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Starts_Days_Or_After_End() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Starts_Days_Or_After_End: Interval[@2023-01-01, @2023-03-31] starts same day or after end Interval[@2023-04-01, @2023-04-30] @@ -129,7 +129,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Ends_Months_Or_Before_Start() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Ends_Months_Or_Before_Start: Interval[@2023-01, @2023-03] ends same month or before start Interval[@2023-04, @2023-06] @@ -157,7 +157,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Ends_Months_Or_Before_End() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Ends_Months_Or_Before_End: Interval[@2023-01, @2023-03] ends same month or before end Interval[@2023-04, @2023-06] @@ -185,7 +185,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Ends_Months_Or_After_Start() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Ends_Months_Or_After_Start: Interval[@2023-01, @2023-03] ends same month or after start Interval[@2023-04, @2023-06] @@ -213,7 +213,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Ends_Months_Or_After_End() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Ends_Months_Or_After_End: Interval[@2023-01, @2023-03] ends same month or after end Interval[@2023-04, @2023-06] @@ -245,7 +245,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Days_Or_Before_Start() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Starts_Days_Or_Before_Start: Interval[@2023-01-01, @2023-03-31] same day or before start Interval[@2023-04-01, @2023-04-30] @@ -273,7 +273,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Days_Or_Before_End() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Days_Or_Before_End: Interval[@2023-01-01, @2023-03-31] same day or before end Interval[@2023-04-01, @2023-04-30] @@ -301,7 +301,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Days_Or_After_Start() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Days_Or_After_Start: Interval[@2023-01-01, @2023-03-31] same day or after start Interval[@2023-04-01, @2023-04-30] @@ -329,7 +329,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Days_Or_After_End() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Days_Or_After_End: Interval[@2023-01-01, @2023-03-31] same day or after end Interval[@2023-04-01, @2023-04-30] @@ -357,7 +357,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Months_Or_Before_Start() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Months_Or_Before_Start: Interval[@2023-01, @2023-03] same month or before start Interval[@2023-04, @2023-06] @@ -385,7 +385,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Months_Or_Before_End() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Months_Or_Before_End: Interval[@2023-01, @2023-03] same month or before end Interval[@2023-04, @2023-06] @@ -413,7 +413,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Months_Or_After_Start() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Ends_Months_Or_After_Start: Interval[@2023-01, @2023-03] same month or after start Interval[@2023-04, @2023-06] @@ -441,7 +441,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Months_Or_After_End() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Months_Or_After_End: Interval[@2023-01, @2023-03] same month or after end Interval[@2023-04, @2023-06] @@ -473,7 +473,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Starts_Days_Or_Before() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Starts_Days_Or_Before: Interval[@2023-01-01, @2023-03-31] starts same day or before Interval[@2023-04-01, @2023-04-30] @@ -501,7 +501,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Ends_Days_Or_Before() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Ends_Days_Or_Before: Interval[@2023-01-01, @2023-03-31] ends same day or before Interval[@2023-04-01, @2023-04-30] @@ -529,7 +529,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Starts_Days_Or_After() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Starts_Days_Or_After_Start: Interval[@2023-01-01, @2023-03-31] starts same day or after Interval[@2023-04-01, @2023-04-30] @@ -558,7 +558,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Ends_Months_Or_Before() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Ends_Months_Or_Before: Interval[@2023-01, @2023-03] ends same month or before Interval[@2023-04, @2023-06] @@ -587,7 +587,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Ends_Months_Or_After() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Ends_Months_Or_After: Interval[@2023-01, @2023-03] ends same month or after Interval[@2023-04, @2023-06] @@ -620,7 +620,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Days_Or_Before() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Starts_Days_Or_Before: Interval[@2023-01-01, @2023-03-31] same day or before Interval[@2023-04-01, @2023-04-30] @@ -648,7 +648,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Days_Or_After() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Days_Or_After: Interval[@2023-01-01, @2023-03-31] same day or after Interval[@2023-04-01, @2023-04-30] @@ -677,7 +677,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Days_Same() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Days_Or_After: Interval[@2023-01-01, @2023-03-31] same day as Interval[@2023-04-01, @2023-04-30] diff --git a/Cql/CqlToElmTests/ContextDefTest.cs b/Cql/CqlToElmTests/(tests)/ContextDefTest.cs similarity index 87% rename from Cql/CqlToElmTests/ContextDefTest.cs rename to Cql/CqlToElmTests/(tests)/ContextDefTest.cs index 8fd1c21d3..9e67cdecb 100644 --- a/Cql/CqlToElmTests/ContextDefTest.cs +++ b/Cql/CqlToElmTests/(tests)/ContextDefTest.cs @@ -9,7 +9,7 @@ public class ContextDefTest : Base [TestMethod] public void Context_Of_Known_Model() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library UsingTest version '1.0.0' using FHIR @@ -38,7 +38,7 @@ context Observation [TestMethod] public void Context_Of_Unknown_Model() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library UsingTest version '1.0.0' using FHIR @@ -50,7 +50,7 @@ context FHIRX.Patient [TestMethod] public void Context_UnknonwType_on_Known_Model() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library UsingTest version '1.0.0' using FHIR @@ -62,7 +62,7 @@ context FHIR.doesnotexist [TestMethod] public void Context_Not_A_Model() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library UsingTest version '1.0.0' define derp: false @@ -74,7 +74,7 @@ context derp.herp [TestMethod] public void Context_Of_Unknown_Type() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library UsingTest version '1.0.0' using FHIR @@ -86,7 +86,7 @@ context ObservationX [TestMethod] public void Context_Unfiltered_Retrieve_Null_Context() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library UsingTest version '1.0.0' using FHIR version '4.0.1' diff --git a/Cql/CqlToElmTests/ConvertTest.cs b/Cql/CqlToElmTests/(tests)/ConvertTest.cs similarity index 78% rename from Cql/CqlToElmTests/ConvertTest.cs rename to Cql/CqlToElmTests/(tests)/ConvertTest.cs index 1ef2ca43b..075f1dcdb 100644 --- a/Cql/CqlToElmTests/ConvertTest.cs +++ b/Cql/CqlToElmTests/(tests)/ConvertTest.cs @@ -9,14 +9,14 @@ public class ConvertTest : Base [TestMethod] public void Convert_Integer_to_String() { - var library = CreateCqlApi().MakeLibraryFromExpression("convert 5 to String"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("convert 5 to String"); library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); } [TestMethod] public void Convert_String_to_DateTime() { - var library = CreateCqlApi().MakeLibraryFromExpression("ToDateTime('2014-01-01T12:05:05.955-01:15')"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("ToDateTime('2014-01-01T12:05:05.955-01:15')"); var toDateTime = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(toDateTime, library); var dt = result.Should().BeOfType().Subject; @@ -28,7 +28,7 @@ public void Convert_String_to_DateTime() [TestMethod] public void Convert_Code_To_Concept() { - var library = CreateCqlApi().MakeLibraryFromExpression("ToConcept(Code { code: '8480-6' })"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("ToConcept(Code { code: '8480-6' })"); var toConcept = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(toConcept, library); } @@ -36,7 +36,7 @@ public void Convert_Code_To_Concept() [TestMethod] public void Convert_Quantity_To_Weeks() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Test version '1.0.0' diff --git a/Cql/CqlToElmTests/CrossLibraryTest.cs b/Cql/CqlToElmTests/(tests)/CrossLibraryTest.cs similarity index 83% rename from Cql/CqlToElmTests/CrossLibraryTest.cs rename to Cql/CqlToElmTests/(tests)/CrossLibraryTest.cs index db22cd150..b857802c1 100644 --- a/Cql/CqlToElmTests/CrossLibraryTest.cs +++ b/Cql/CqlToElmTests/(tests)/CrossLibraryTest.cs @@ -8,16 +8,16 @@ public class CrossLibraryTest : Base [TestMethod] public void ExpressionRef_Across_Library() { - var cqlApi = CreateCqlApi(); + var cqlToolkit = CreateFluentCqlToolkit(); - var foo = cqlApi.MakeLibrary(""" + var foo = cqlToolkit.MakeLibrary(""" library Foo version '1.0.0' define F: 'foo' """); foo.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); - var bar = cqlApi.MakeLibrary(""" + var bar = cqlToolkit.MakeLibrary(""" library Bar version '1.0.0' include Foo version '1.0.0' called foo @@ -30,15 +30,15 @@ include Foo version '1.0.0' called foo [TestMethod] public void ExpressionRef_Across_Library_NotFound() { - var cqlApi = CreateCqlApi(); - var foo = cqlApi.MakeLibrary(""" + var cqlToolkit = CreateFluentCqlToolkit(); + var foo = cqlToolkit.MakeLibrary(""" library Foo version '1.0.0' define F: 'foo' """); foo.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); - cqlApi.MakeLibrary(""" + cqlToolkit.MakeLibrary(""" library Bar version '1.0.0' include Foo version '1.0.0' called foo @@ -51,15 +51,15 @@ include Foo version '1.0.0' called foo [TestMethod] public void FunctionRef_Across_Library() { - var cqlApi = CreateCqlApi(); - var foo = cqlApi.MakeLibrary(""" + var cqlToolkit = CreateFluentCqlToolkit(); + var foo = cqlToolkit.MakeLibrary(""" library Foo version '1.0.0' define function Foo(): 'foo' """); foo.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); - var bar = cqlApi.MakeLibrary(""" + var bar = cqlToolkit.MakeLibrary(""" library Bar version '1.0.0' include Foo version '1.0.0' called foo @@ -73,15 +73,15 @@ include Foo version '1.0.0' called foo [TestMethod] public void FunctionRef_Across_Library_NotFound() { - var cqlApi = CreateCqlApi(); - var foo = cqlApi.MakeLibrary(""" + var cqlToolkit = CreateFluentCqlToolkit(); + var foo = cqlToolkit.MakeLibrary(""" library Foo version '1.0.0' define function Foo(): 'foo' """); foo.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); - cqlApi.MakeLibrary(""" + cqlToolkit.MakeLibrary(""" library Bar version '1.0.0' include Foo version '1.0.0' called foo diff --git a/Cql/CqlToElmTests/DifferenceTest.cs b/Cql/CqlToElmTests/(tests)/DifferenceTest.cs similarity index 93% rename from Cql/CqlToElmTests/DifferenceTest.cs rename to Cql/CqlToElmTests/(tests)/DifferenceTest.cs index 304dd43bb..8589bba46 100644 --- a/Cql/CqlToElmTests/DifferenceTest.cs +++ b/Cql/CqlToElmTests/(tests)/DifferenceTest.cs @@ -8,7 +8,7 @@ public class DifferenceTest : Base [TestMethod] public void Difference_Between_Days() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DifferenceTest version '1.0.0' define private Difference_Between_Days: difference in days between @2023-01-01 and @2023-01-31 @@ -30,7 +30,7 @@ library DifferenceTest version '1.0.0' [TestMethod] public void Difference_Between_Months() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DifferenceTest version '1.0.0' define private Difference_Between_Months: difference in months between @2023-01-01 and @2023-02-01 @@ -52,7 +52,7 @@ library DifferenceTest version '1.0.0' [TestMethod] public void Difference_Between_Weeks() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DifferenceTest version '1.0.0' define private Difference_Between_Months: difference in weeks between @2023-01-01 and @2023-01-08 @@ -76,7 +76,7 @@ library DifferenceTest version '1.0.0' [TestMethod] public void Difference_Between_Years() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DifferenceTest version '1.0.0' define private Difference_Between_Months: difference in years between @2023-01-01 and @2024-02-01 @@ -98,7 +98,7 @@ library DifferenceTest version '1.0.0' [TestMethod] public void Difference_Between_Date_In_Hours() => - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library DifferenceTest version '1.0.0' define private Difference_Between_Date_In_Hours: difference in hours between @2023-01-01 and @2024-02-01 @@ -107,7 +107,7 @@ library DifferenceTest version '1.0.0' [TestMethod] public void Difference_Between_Hours() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DifferenceTest version '1.0.0' define private Difference_Between_Hours: difference in hours between @T12:00:00 and @T20:00:00 @@ -130,7 +130,7 @@ library DifferenceTest version '1.0.0' [TestMethod] public void Difference_Between_Minutes() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DifferenceTest version '1.0.0' define private Difference_Between_Minutes: difference in minutes between @T12:00:00 and @T20:00:00 @@ -153,7 +153,7 @@ library DifferenceTest version '1.0.0' [TestMethod] public void Difference_Between_Seconds() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DifferenceTest version '1.0.0' define private Difference_Between_Minutes: difference in seconds between @T12:00:00 and @T12:00:30 @@ -176,7 +176,7 @@ library DifferenceTest version '1.0.0' [TestMethod] public void Difference_Between_Milliseconds() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DifferenceTest version '1.0.0' define private Difference_Between_Milliseconds: difference in milliseconds between @T12:00:00.100 and @T12:00:00.300 @@ -198,7 +198,7 @@ library DifferenceTest version '1.0.0' [TestMethod] public void Difference_Between_Time_In_Days() => - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library DifferenceTest version '1.0.0' define private Difference_Between_Milliseconds: difference in days between @T12:00:00.100 and @T12:00:00.300 @@ -207,7 +207,7 @@ library DifferenceTest version '1.0.0' [TestMethod] public void Difference_Between_DateTimes() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DifferenceTest version '1.0.0' define private Difference_Between_DateTimes_Years: difference in years between @2023-01-01T12:00:00.100 and @2024-01-01T12:00:00.100 @@ -224,7 +224,7 @@ library DifferenceTest version '1.0.0' [TestMethod] public void Difference_Between_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DifferenceTest version '1.0.0' define private Difference_Between_Months: difference in weeks between null and @2023-01-08 @@ -245,7 +245,7 @@ library DifferenceTest version '1.0.0' [TestMethod] public void Difference_Between_Null_Null() => - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library DifferenceTest version '1.0.0' define private Difference_Between_Months: difference in weeks between null and null diff --git a/Cql/CqlToElmTests/DistinctTest.cs b/Cql/CqlToElmTests/(tests)/DistinctTest.cs similarity index 82% rename from Cql/CqlToElmTests/DistinctTest.cs rename to Cql/CqlToElmTests/(tests)/DistinctTest.cs index 204cf63bd..427db6024 100644 --- a/Cql/CqlToElmTests/DistinctTest.cs +++ b/Cql/CqlToElmTests/(tests)/DistinctTest.cs @@ -8,7 +8,7 @@ public class DistinctTest : Base [TestMethod] public void DistinctABCABC() { - var library = CreateCqlApi().MakeLibraryFromExpression("distinct { 'a', 'b', 'c', 'a', 'b', 'c'}"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("distinct { 'a', 'b', 'c', 'a', 'b', 'c'}"); var distinct = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run?>(distinct, library)!.ToArray(); result.Length.Should().Be(3); diff --git a/Cql/CqlToElmTests/DivisionTest.cs b/Cql/CqlToElmTests/(tests)/DivisionTest.cs similarity index 95% rename from Cql/CqlToElmTests/DivisionTest.cs rename to Cql/CqlToElmTests/(tests)/DivisionTest.cs index 9fb9c8666..42d4bc0a9 100644 --- a/Cql/CqlToElmTests/DivisionTest.cs +++ b/Cql/CqlToElmTests/(tests)/DivisionTest.cs @@ -13,7 +13,7 @@ public class DivisionTest : Base [TestMethod] public void Divide_Integer_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Integer_by_Integer version '1.0.0' define private Divide_Integer_by_Integer: 2 / 4 @@ -58,7 +58,7 @@ library Divide_Integer_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -69,7 +69,7 @@ library Divide_Integer_by_Integer version '1.0.0' [TestMethod] public void Divide_Integer_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Integer_by_Long version '1.0.0' define private Divide_Integer_by_Long: 2 / 3L @@ -114,7 +114,7 @@ library Divide_Integer_by_Long version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -125,7 +125,7 @@ library Divide_Integer_by_Long version '1.0.0' [TestMethod] public void Divide_Integer_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Integer_by_Decimal version '1.0.0' define private Divide_Integer_by_Decimal: 2 / 3.0 @@ -170,7 +170,7 @@ library Divide_Integer_by_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -181,7 +181,7 @@ library Divide_Integer_by_Decimal version '1.0.0' [TestMethod] public void Divide_Integer_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Integer_by_Quantity version '1.0.0' define private Divide_Integer_by_Quantity: 10 / 2.0 '1' @@ -226,7 +226,7 @@ library Divide_Integer_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -241,7 +241,7 @@ library Divide_Integer_by_Quantity version '1.0.0' [TestMethod] public void Divide_Integer_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Integer_by_Null version '1.0.0' define private Divide_Integer_by_Null: 1 / null @@ -285,7 +285,7 @@ library Divide_Integer_by_Null version '1.0.0' Assert.IsNotNull(lhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", lhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -295,7 +295,7 @@ library Divide_Integer_by_Null version '1.0.0' [TestMethod] public void Divide_Null_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Null_by_Integer version '1.0.0' define private Divide_Null_by_Integer: null / 1 @@ -339,7 +339,7 @@ library Divide_Null_by_Integer version '1.0.0' Assert.IsNotNull(rhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -353,7 +353,7 @@ library Divide_Null_by_Integer version '1.0.0' [TestMethod] public void Divide_Long_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Long_by_Integer version '1.0.0' define private Divide_Long_by_Integer: 10L / 2 @@ -398,7 +398,7 @@ library Divide_Long_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -409,7 +409,7 @@ library Divide_Long_by_Integer version '1.0.0' [TestMethod] public void Divide_Long_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Long_by_Long version '1.0.0' define private Divide_Long_by_Long: 100L / 10L @@ -454,7 +454,7 @@ library Divide_Long_by_Long version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -465,7 +465,7 @@ library Divide_Long_by_Long version '1.0.0' [TestMethod] public void Divide_Long_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Long_by_Decimal version '1.0.0' define private Divide_Long_by_Decimal: -3L / 2.0 @@ -510,7 +510,7 @@ library Divide_Long_by_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -521,7 +521,7 @@ library Divide_Long_by_Decimal version '1.0.0' [TestMethod] public void Divide_Long_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Long_by_Quantity version '1.0.0' define private Divide_Long_by_Quantity: 20L / 5.0 '1' @@ -566,7 +566,7 @@ library Divide_Long_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -580,7 +580,7 @@ library Divide_Long_by_Quantity version '1.0.0' [TestMethod] public void Divide_Long_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Long_by_Null version '1.0.0' define private Divide_Long_by_Null: 1L / null @@ -624,7 +624,7 @@ library Divide_Long_by_Null version '1.0.0' Assert.IsNotNull(lhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", lhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -634,7 +634,7 @@ library Divide_Long_by_Null version '1.0.0' [TestMethod] public void Divide_Null_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Null_by_Long version '1.0.0' define private Divide_Null_by_Long: null / 1L @@ -678,7 +678,7 @@ library Divide_Null_by_Long version '1.0.0' Assert.IsNotNull(rhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -692,7 +692,7 @@ library Divide_Null_by_Long version '1.0.0' [TestMethod] public void Divide_Decimal_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Decimal_by_Integer version '1.0.0' define private Divide_Decimal_by_Integer: 0.0 / 3 @@ -737,7 +737,7 @@ library Divide_Decimal_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -748,7 +748,7 @@ library Divide_Decimal_by_Integer version '1.0.0' [TestMethod] public void Divide_Decimal_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DefaultConverter version '1.0.0' define private DefaultConverter: 5.0 / 5L @@ -793,7 +793,7 @@ library DefaultConverter version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -804,7 +804,7 @@ library DefaultConverter version '1.0.0' [TestMethod] public void Divide_Decimal_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Decimal_by_Decimal version '1.0.0' define private Divide_Decimal_by_Decimal: -10.0 / 10.0 @@ -849,7 +849,7 @@ library Divide_Decimal_by_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -860,7 +860,7 @@ library Divide_Decimal_by_Decimal version '1.0.0' [TestMethod] public void Divide_Decimal_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Decimal_by_Quantity version '1.0.0' define private Divide_Decimal_by_Quantity: 3.0 / 2.0 '1' @@ -905,7 +905,7 @@ library Divide_Decimal_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -919,7 +919,7 @@ library Divide_Decimal_by_Quantity version '1.0.0' [TestMethod] public void Divide_Decimal_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Decimal_by_Null version '1.0.0' define private Divide_Decimal_by_Null: 1.0 / null @@ -963,7 +963,7 @@ library Divide_Decimal_by_Null version '1.0.0' Assert.IsNotNull(lhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", lhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -973,7 +973,7 @@ library Divide_Decimal_by_Null version '1.0.0' [TestMethod] public void Divide_Null_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Null_by_Decimal version '1.0.0' define private Divide_Null_by_Decimal: null / 1.0 @@ -1017,7 +1017,7 @@ library Divide_Null_by_Decimal version '1.0.0' Assert.IsNotNull(rhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -1031,7 +1031,7 @@ library Divide_Null_by_Decimal version '1.0.0' [TestMethod] public void Divide_Quantity_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Quantity_by_Quantity version '1.0.0' define private Divide_Quantity_by_Quantity: 3.0 '1' / 2.0 '1' @@ -1076,7 +1076,7 @@ library Divide_Quantity_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -1090,7 +1090,7 @@ library Divide_Quantity_by_Quantity version '1.0.0' [TestMethod] public void Divide_Quantity_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Quantity_by_Null version '1.0.0' define private Divide_Quantity_by_Null: 3.0 '1' / null @@ -1135,7 +1135,7 @@ library Divide_Quantity_by_Null version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -1145,7 +1145,7 @@ library Divide_Quantity_by_Null version '1.0.0' [TestMethod] public void Divide_Null_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Divide_Null_by_Quantity version '1.0.0' define private Divide_Null_by_Quantity: null / 3.0 '1' @@ -1190,7 +1190,7 @@ library Divide_Null_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); diff --git a/Cql/CqlToElmTests/DurationTest.cs b/Cql/CqlToElmTests/(tests)/DurationTest.cs similarity index 93% rename from Cql/CqlToElmTests/DurationTest.cs rename to Cql/CqlToElmTests/(tests)/DurationTest.cs index e2bea68b0..6559c61fc 100644 --- a/Cql/CqlToElmTests/DurationTest.cs +++ b/Cql/CqlToElmTests/(tests)/DurationTest.cs @@ -8,7 +8,7 @@ public class DurationTest : Base [TestMethod] public void Duration_Between_Days() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define private Duration_Between_Days: duration in days between @2023-01-01 and @2023-01-31 @@ -32,7 +32,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Duration_Between_Days_Shortform() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define private Duration_Between_Days: days between @2023-01-01 and @2023-01-31 @@ -55,7 +55,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Duration_Between_Months() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define private Duration_Between_Months: duration in months between @2023-01-01 and @2023-02-01 @@ -77,7 +77,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Duration_Between_Weeks() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define private Duration_Between_Months: duration in weeks between @2023-01-01 and @2023-01-08 @@ -101,7 +101,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Duration_Between_Years() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define private Duration_Between_Months: duration in years between @2023-01-01 and @2024-02-01 @@ -123,7 +123,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Duration_Between_Date_In_Hours() => - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define private Duration_Between_Date_In_Hours: duration in hours between @2023-01-01 and @2024-02-01 @@ -132,7 +132,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Duration_Between_Hours() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define private Duration_Between_Hours: duration in hours between @T12:00:00 and @T20:00:00 @@ -155,7 +155,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Duration_Between_Minutes() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define private Duration_Between_Minutes: duration in minutes between @T12:00:00 and @T20:00:00 @@ -178,7 +178,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Duration_Between_Seconds() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define private Duration_Between_Minutes: duration in seconds between @T12:00:00 and @T12:00:30 @@ -201,7 +201,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Duration_Between_Milliseconds() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define private Duration_Between_Milliseconds: duration in milliseconds between @T12:00:00.100 and @T12:00:00.300 @@ -223,7 +223,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Duration_Between_Time_In_Days() => - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define private Duration_Between_Milliseconds: duration in days between @T12:00:00.100 and @T12:00:00.300 @@ -232,7 +232,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Duration_Between_DateTimes() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define private Duration_Between_DateTimes_Years: duration in years between @2023-01-01T12:00:00.100 and @2024-01-01T12:00:00.100 @@ -249,7 +249,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Duration_Between_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define private Duration_Between_Months: duration in weeks between null and @2023-01-08 @@ -270,7 +270,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Duration_Between_Null_Null() => - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define private Duration_Between_Months: duration in weeks between null and null @@ -279,7 +279,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Duration_In_Days() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define d: duration in days of Interval[@2023-01-01, @2023-01-31] @@ -312,7 +312,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Duration_In_Days_MixedPrecision() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define d: duration in days of Interval[@2023-01-01, @2023-01-31T12:30:45] @@ -330,7 +330,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Duration_In_Days_NonInterval() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define d: duration in days of 1 @@ -340,7 +340,7 @@ library DurationTest version '1.0.0' [TestMethod] public void Difference_In_Years() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library DurationTest version '1.0.0' define d: difference in years of Interval[@2023-01-01, @2023-01-31] diff --git a/Cql/CqlToElmTests/EqualsTest.cs b/Cql/CqlToElmTests/(tests)/EqualsTest.cs similarity index 94% rename from Cql/CqlToElmTests/EqualsTest.cs rename to Cql/CqlToElmTests/(tests)/EqualsTest.cs index 4a4065210..30914bd5e 100644 --- a/Cql/CqlToElmTests/EqualsTest.cs +++ b/Cql/CqlToElmTests/(tests)/EqualsTest.cs @@ -11,7 +11,7 @@ public class EqualsTest : Base [TestMethod] public void Integer_Equals_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_Equals_Integer: 1 = 1 @@ -56,7 +56,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -67,7 +67,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_Equals_Integer_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_Equals_Integer_False: 1 = 2 @@ -112,7 +112,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -123,7 +123,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_Equals_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_Equals_Long: 1 = 1L @@ -168,7 +168,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -179,7 +179,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_Equals_Decimal_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_Equals_Decimal_False: 1 = 1.01 @@ -224,7 +224,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -236,7 +236,7 @@ library EqualsTest version '1.0.0' public void Integer_Equals_Quantity() { // 1 converts to 1.0 '1' and '1' units are equal to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_Equals_Quantity: 1 = 1.0 'g' @@ -281,7 +281,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -292,7 +292,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_Equals_Quantity_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_Equals_Quantity_False: 1 = 1.01 '1' @@ -337,7 +337,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -348,7 +348,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_Equals_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("1 = null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("1 = null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -356,7 +356,7 @@ public void Integer_Equals_Null() [TestMethod] public void Null_Equals_Integer() { - var library = CreateCqlApi().MakeLibraryFromExpression("null = 1"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null = 1"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -368,7 +368,7 @@ public void Null_Equals_Integer() [TestMethod] public void Long_Equals_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_Equals_Long: 1L = 1L @@ -413,7 +413,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -424,7 +424,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_Equals_Long_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_Equals_Long_False: 1L = 2L @@ -469,7 +469,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -480,7 +480,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_Equals_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_Equals_Long: 1L = 1 @@ -525,7 +525,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -536,7 +536,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_Equals_Decimal_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_DoesNotEqual_Decimal: 1L = 1.01 @@ -581,7 +581,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -593,7 +593,7 @@ library EqualsTest version '1.0.0' public void Long_Equals_Quantity() { // 1L converts to 1.0 '1' and '1' units are equal to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_Equals_Quantity: 1L = 1.0 'g' @@ -638,7 +638,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -649,7 +649,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_DoesNotEqual_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_DoesNotEqual_Quantity: 1L = 1.01 '1' @@ -694,7 +694,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -705,7 +705,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_Equals_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("1L = null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("1L = null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -713,7 +713,7 @@ public void Long_Equals_Null() [TestMethod] public void Null_Equals_Long() { - var library = CreateCqlApi().MakeLibraryFromExpression("null = 1L"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null = 1L"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -725,7 +725,7 @@ public void Null_Equals_Long() [TestMethod] public void Decimal_Equals_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_Equals_Decimal: 1.0 = 1.0 @@ -770,7 +770,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -781,7 +781,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_Equals_Decimal_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_Equals_Decimal_False: 1.0 = 2.0 @@ -826,7 +826,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -837,7 +837,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_Equals_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_Equals_Decimal: 1.0 = 1 @@ -882,7 +882,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -893,7 +893,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_Equals_Long_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_DoesNotEqual_Decimal: 2.0 = 1L @@ -938,7 +938,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -950,7 +950,7 @@ library EqualsTest version '1.0.0' public void Decimal_Equals_Quantity() { // 1.0 converts to 1.0 '1' and '1' units are equal to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_Equals_Quantity: 1.0 = 1.0 'g' @@ -995,7 +995,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1006,7 +1006,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_DoesNotEqual_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_DoesNotEqual_Quantity: 1.0 = 1.01 '1' @@ -1051,7 +1051,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1062,7 +1062,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_Equals_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("1.0 = null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("1.0 = null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -1070,7 +1070,7 @@ public void Decimal_Equals_Null() [TestMethod] public void Null_Equals_Decimal() { - var library = CreateCqlApi().MakeLibraryFromExpression("null = 1.0"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null = 1.0"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -1082,7 +1082,7 @@ public void Null_Equals_Decimal() [TestMethod] public void Quantity_Equals_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_Equals_Quantity: 1.0 '1' = 1.0 '1' @@ -1127,7 +1127,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1138,7 +1138,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_Equals_Quantity_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_Equals_Quantity_False: 1.0 '1' = 2.0 '1' @@ -1183,7 +1183,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1194,7 +1194,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_Equals_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_Equals_Quantity: 1.0 '1' = 1 @@ -1239,7 +1239,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1250,7 +1250,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_Equals_Long_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_DoesNotEqual_Quantity: 2.0 '1' = 1L @@ -1295,7 +1295,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1307,7 +1307,7 @@ library EqualsTest version '1.0.0' public void Quantity_Equals_Decimal() { // 1.0 converts to 1.0 '1' and '1' units are equal to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_Equals_Decimal: 1.0 'g' = 1.0 @@ -1352,7 +1352,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1363,7 +1363,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_DoesNotEqual_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_DoesNotEqual_Quantity: 1.0 = 1.01 '1' @@ -1408,7 +1408,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1419,7 +1419,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_Equals_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("1.0 '1' = null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("1.0 '1' = null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -1427,7 +1427,7 @@ public void Quantity_Equals_Null() [TestMethod] public void Null_Equals_Quantity() { - var library = CreateCqlApi().MakeLibraryFromExpression("null = 1.0 '1'"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null = 1.0 '1'"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -1438,7 +1438,7 @@ public void Null_Equals_Quantity() [TestMethod] public void String_Equals_String() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private String_Equals_String: 'hello' = 'hello' @@ -1483,7 +1483,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}String", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1494,7 +1494,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void String_Equals_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("'hello' = null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("'hello' = null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -1502,7 +1502,7 @@ public void String_Equals_Null() [TestMethod] public void Null_Equals_String() { - var library = CreateCqlApi().MakeLibraryFromExpression("null = 'hello'"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null = 'hello'"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -1511,7 +1511,7 @@ public void Null_Equals_String() [TestMethod] public void Date_Equals_Date() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Date_Equals_Date: @2023 = @2023 @@ -1556,7 +1556,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Date", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1567,7 +1567,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Date_Equals_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("@2023 = null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("@2023 = null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -1575,7 +1575,7 @@ public void Date_Equals_Null() [TestMethod] public void Null_Equals_Date() { - var library = CreateCqlApi().MakeLibraryFromExpression("null = @2023"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null = @2023"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -1583,7 +1583,7 @@ public void Null_Equals_Date() [TestMethod] public void DateTimeList_Equals_DateTimeList() { - var lib = CreateCqlApi().MakeLibraryFromExpression("{ DateTime(2016), DateTime(2015), DateTime(2010)} = { @2016T, @2015T, @2010T }"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("{ DateTime(2016), DateTime(2015), DateTime(2010)} = { @2016T, @2015T, @2010T }"); var equal = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); equal.operand.Should().HaveCount(2); equal.operand[0].Should().HaveType(SystemTypes.DateTimeType.ToListType()); diff --git a/Cql/CqlToElmTests/EquivalentTest.cs b/Cql/CqlToElmTests/(tests)/EquivalentTest.cs similarity index 94% rename from Cql/CqlToElmTests/EquivalentTest.cs rename to Cql/CqlToElmTests/(tests)/EquivalentTest.cs index e57878e56..8e2d41c36 100644 --- a/Cql/CqlToElmTests/EquivalentTest.cs +++ b/Cql/CqlToElmTests/(tests)/EquivalentTest.cs @@ -11,7 +11,7 @@ public class EquivalentTest : Base [TestMethod] public void Integer_EquivalentTo_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_EquivalentTo_Integer: 1 ~ 1 @@ -56,7 +56,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -67,7 +67,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_EquivalentTo_Integer_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_EquivalentTo_Integer_False: 1 ~ 2 @@ -112,7 +112,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -123,7 +123,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_EquivalentTo_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_EquivalentTo_Long: 1 ~ 1L @@ -168,7 +168,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -179,7 +179,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_EquivalentTo_Decimal_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_EquivalentTo_Decimal_False: 1 ~ 2.01 @@ -224,7 +224,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -236,7 +236,7 @@ library EqualsTest version '1.0.0' public void Integer_EquivalentTo_Quantity() { // 1 converts to 1.0 '1' and '1' units are equal to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_EquivalentTo_Quantity: 1 ~ 1.0 'g' @@ -281,7 +281,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -292,7 +292,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_EquivalentTo_Quantity_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_EquivalentTo_Quantity_False: 1 ~ 2.0 '1' @@ -337,7 +337,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -348,7 +348,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_EquivalentTo_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("1 ~ null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("1 ~ null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, false); } @@ -356,7 +356,7 @@ public void Integer_EquivalentTo_Null() [TestMethod] public void Null_EquivalentTo_Integer() { - var library = CreateCqlApi().MakeLibraryFromExpression("null ~ 1"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null ~ 1"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, false); } @@ -368,7 +368,7 @@ public void Null_EquivalentTo_Integer() [TestMethod] public void Long_EquivalentTo_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_EquivalentTo_Long: 1L ~ 1L @@ -413,7 +413,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -424,7 +424,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_EquivalentTo_Long_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_EquivalentTo_Long_False: 1L ~ 2L @@ -469,7 +469,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -480,7 +480,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_EquivalentTo_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_EquivalentTo_Long: 1L ~ 1 @@ -525,7 +525,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -536,7 +536,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_EquivalentTo_Decimal_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_EquivalentTo_Decimal_False: 1L ~ 2.0 @@ -581,7 +581,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -593,7 +593,7 @@ library EqualsTest version '1.0.0' public void Long_EquivalentTo_Quantity() { // 1L converts to 1.0 '1' and '1' units are equal to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_EquivalentTo_Quantity: 1L ~ 1.0 'g' @@ -638,7 +638,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -649,7 +649,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_EquivalentTo_Quantity_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_EquivalentTo_Quantity_False: 1L ~ 2 '1' @@ -694,7 +694,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -705,7 +705,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_EquivalentTo_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("1L ~ null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("1L ~ null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, false); } @@ -713,7 +713,7 @@ public void Long_EquivalentTo_Null() [TestMethod] public void Null_EquivalentTo_Long() { - var library = CreateCqlApi().MakeLibraryFromExpression("null ~ 1L"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null ~ 1L"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, false); } @@ -725,7 +725,7 @@ public void Null_EquivalentTo_Long() [TestMethod] public void Decimal_EquivalentTo_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_EquivalentTo_Decimal: 1.0 ~ 1.0 @@ -770,7 +770,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -781,7 +781,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_EquivalentTo_Decimal_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_EquivalentTo_Decimal_False: 1.0 ~ 2.0 @@ -826,7 +826,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -837,7 +837,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_EquivalentTo_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_EquivalentTo_Decimal: 1.0 ~ 1 @@ -882,7 +882,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -893,7 +893,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_EquivalentTo_Long_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_EquivalentTo_Long_False: 2.0 ~ 1L @@ -938,7 +938,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -950,7 +950,7 @@ library EqualsTest version '1.0.0' public void Decimal_EquivalentTo_Quantity() { // 1.0 converts to 1.0 '1' and '1' units are equal to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_EquivalentTo_Quantity: 1.0 ~ 1.0 'g' @@ -995,7 +995,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1006,7 +1006,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_EquivalentTo_Quantity_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_EquivalentTo_Quantity_False: 1.0 ~ 2.0 '1' @@ -1051,7 +1051,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1062,7 +1062,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_EquivalentTo_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("1.0 ~ null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("1.0 ~ null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, false); } @@ -1070,7 +1070,7 @@ public void Decimal_EquivalentTo_Null() [TestMethod] public void Null_EquivalentTo_Decimal() { - var library = CreateCqlApi().MakeLibraryFromExpression("null ~ 1.0"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null ~ 1.0"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, false); } @@ -1082,7 +1082,7 @@ public void Null_EquivalentTo_Decimal() [TestMethod] public void Quantity_EquivalentTo_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_EquivalentTo_Quantity: 1.0 '1' ~ 1.0 '1' @@ -1127,7 +1127,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1138,7 +1138,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_EquivalentTo_Quantity_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_EquivalentTo_Quantity_False: 1.0 '1' ~ 2.0 '1' @@ -1183,7 +1183,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1194,7 +1194,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_EquivalentTo_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_EquivalentTo_Quantity: 1.0 '1' ~ 1 @@ -1239,7 +1239,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1250,7 +1250,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_EquivalentTo_Long_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_EquivalentTo_Long_False: 2.0 '1' ~ 1L @@ -1295,7 +1295,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1307,7 +1307,7 @@ library EqualsTest version '1.0.0' public void Quantity_EquivalentTo_Decimal() { // 1.0 converts to 1.0 '1' and '1' units are equal to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_EquivalentTo_Decimal: 1.0 'g' ~ 1.0 @@ -1352,7 +1352,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1363,7 +1363,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_EquivalentTo_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("1.0 '1' ~ null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("1.0 '1' ~ null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, false); } @@ -1371,7 +1371,7 @@ public void Quantity_EquivalentTo_Null() [TestMethod] public void Null_EquivalentTo_Quantity() { - var library = CreateCqlApi().MakeLibraryFromExpression("null ~ 1.0 '1'"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null ~ 1.0 '1'"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, false); } @@ -1382,7 +1382,7 @@ public void Null_EquivalentTo_Quantity() [TestMethod] public void String_EquivalentTo_String() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private String_EquivalentTo_String: 'hello' ~ 'hello' @@ -1427,7 +1427,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}String", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1438,7 +1438,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void String_EquivalentTo_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("'hello' ~ null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("'hello' ~ null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, false); } @@ -1446,7 +1446,7 @@ public void String_EquivalentTo_Null() [TestMethod] public void Null_EquivalentTo_String() { - var library = CreateCqlApi().MakeLibraryFromExpression("null ~ 'hello'"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null ~ 'hello'"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, false); } diff --git a/Cql/CqlToElmTests/ExistsTest.cs b/Cql/CqlToElmTests/(tests)/ExistsTest.cs similarity index 92% rename from Cql/CqlToElmTests/ExistsTest.cs rename to Cql/CqlToElmTests/(tests)/ExistsTest.cs index 0183d4a2c..d193b0143 100644 --- a/Cql/CqlToElmTests/ExistsTest.cs +++ b/Cql/CqlToElmTests/(tests)/ExistsTest.cs @@ -9,7 +9,7 @@ public class ExistsTest : Base [TestMethod] public void Exists_True() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ExistsTest version '1.0.0' define private Empty_List: exists { 1, 3, 5, 7 } @@ -33,7 +33,7 @@ library ExistsTest version '1.0.0' [TestMethod] public void Exists_Empty_List() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ExistsTest version '1.0.0' define private Empty_List: exists { } @@ -53,7 +53,7 @@ library ExistsTest version '1.0.0' [TestMethod] public void Exists_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ExistsTest version '1.0.0' define private Empty_List: exists null @@ -74,7 +74,7 @@ library ExistsTest version '1.0.0' [TestMethod] public void Exists_List_Nulls() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ExistsTest version '1.0.0' define private Empty_List: exists { null } @@ -98,7 +98,7 @@ library ExistsTest version '1.0.0' private void AssertExists(Exists exists, bool? expected) { - var lambda = CreateElmApi().Lambda(exists); + var lambda = ToFluentElmToolkit().Lambda(exists); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); diff --git a/Cql/CqlToElmTests/ExpandTest.cs b/Cql/CqlToElmTests/(tests)/ExpandTest.cs similarity index 62% rename from Cql/CqlToElmTests/ExpandTest.cs rename to Cql/CqlToElmTests/(tests)/ExpandTest.cs index 2eaddb8f4..9179d945d 100644 --- a/Cql/CqlToElmTests/ExpandTest.cs +++ b/Cql/CqlToElmTests/(tests)/ExpandTest.cs @@ -8,28 +8,28 @@ public class ExpandCollapseTest : Base [TestMethod] public void ExpandUnitUnspecified() { - var lib = CreateCqlApi().MakeLibraryFromExpression("expand { Interval[1, 4], Interval[4, 8], Interval[7, 9] }"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("expand { Interval[1, 4], Interval[4, 8], Interval[7, 9] }"); var expand = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); } [TestMethod] public void ExpandPerDay() { - var lib = CreateCqlApi().MakeLibraryFromExpression("expand { Interval[@2018-01-01, @2018-01-04] } per day"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("expand { Interval[@2018-01-01, @2018-01-04] } per day"); var expand = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); } [TestMethod] public void ExpandPer2Days() { - var lib = CreateCqlApi().MakeLibraryFromExpression("expand { Interval[@2018-01-01, @2018-01-04] } per 2 days"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("expand { Interval[@2018-01-01, @2018-01-04] } per 2 days"); var expand = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); } [TestMethod] public void ExpandIntervalPer2() { - var lib = CreateCqlApi().MakeLibraryFromExpression("expand { Interval [1, 10] } per 2"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("expand { Interval [1, 10] } per 2"); var expand = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); } @@ -37,7 +37,7 @@ public void ExpandIntervalPer2() [TestMethod] public void Expand_List_Interval() { - var lib = CreateCqlApi().MakeLibraryFromExpression("expand { Interval[10.0, 10.0] } per 0.1"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("expand { Interval[10.0, 10.0] } per 0.1"); var expand = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); expand.operand.Length.Should().Be(2); expand.operand[0].Should().HaveType(SystemTypes.DecimalType.ToIntervalType().ToListType()); @@ -48,7 +48,7 @@ public void Expand_List_Interval() [TestMethod] public void CollapseUnitUnspecified() { - var lib = CreateCqlApi().MakeLibraryFromExpression("collapse { Interval[1, 4], Interval[4, 8], Interval[7, 9] }"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("collapse { Interval[1, 4], Interval[4, 8], Interval[7, 9] }"); var expand = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); } @@ -56,7 +56,7 @@ public void CollapseUnitUnspecified() [TestMethod] public void CollapseIntervalPerDay() { - var lib = CreateCqlApi().MakeLibraryFromExpression("collapse { Interval [1, 10] } per day"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("collapse { Interval [1, 10] } per day"); var expand = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); } @@ -64,14 +64,14 @@ public void CollapseIntervalPerDay() [TestMethod] public void CollapseIntervalPer2Day() { - var lib = CreateCqlApi().MakeLibraryFromExpression("collapse { Interval [1, 10] } per 2 day"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("collapse { Interval [1, 10] } per 2 day"); var expand = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); } [TestMethod] public void DateTimeCollapse() { - var lib = CreateCqlApi().MakeLibraryFromExpression("collapse { Interval[DateTime(2012, 1, 1), DateTime(2012, 1, 15)], Interval[DateTime(2012, 1, 10), DateTime(2012, 1, 25)], Interval[DateTime(2012, 5, 10), DateTime(2012, 5, 25)], Interval[DateTime(2012, 5, 20), DateTime(2012, 5, 30)] }"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("collapse { Interval[DateTime(2012, 1, 1), DateTime(2012, 1, 15)], Interval[DateTime(2012, 1, 10), DateTime(2012, 1, 25)], Interval[DateTime(2012, 5, 10), DateTime(2012, 5, 25)], Interval[DateTime(2012, 5, 20), DateTime(2012, 5, 30)] }"); var collapse = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); // expected {Interval [ @2012-01-01T, @2012-01-25T ], Interval [ @2012-05-10T, @2012-05-30T ]} var result = Run(collapse, lib); diff --git a/Cql/CqlToElmTests/FHIRHelpersTest.cs b/Cql/CqlToElmTests/(tests)/FHIRHelpersTest.cs similarity index 89% rename from Cql/CqlToElmTests/FHIRHelpersTest.cs rename to Cql/CqlToElmTests/(tests)/FHIRHelpersTest.cs index 22576f7bb..fa16aa004 100644 --- a/Cql/CqlToElmTests/FHIRHelpersTest.cs +++ b/Cql/CqlToElmTests/(tests)/FHIRHelpersTest.cs @@ -10,7 +10,7 @@ public class FHIRHelpersTest : Base public void FHIRHelpers_To_Elm() { var cql = File.ReadAllText(@"Input\FHIRHelpers-4.0.1.cql"); - var lib = CreateCqlApi().MakeLibrary(cql); + var lib = CreateFluentCqlToolkit().MakeLibrary(cql); lib.GetErrors().Should().BeEmpty(); using var fs = new FileStream("FHIRHelpers-4.0.1.json", FileMode.Create, FileAccess.Write, FileShare.Read); lib.WriteJson(fs, true); @@ -22,19 +22,19 @@ public void FHIRHelpers_To_Elm() public void FHIRHelpers_To_Expressions() { var cql = File.ReadAllText(@"Input\FHIRHelpers-4.0.1.cql"); - var lib = CreateCqlApi().MakeLibrary(cql); + var lib = CreateFluentCqlToolkit().MakeLibrary(cql); lib.GetErrors().Should().BeEmpty(); using var fs = new FileStream("FHIRHelpers-4.0.1.json", FileMode.Create, FileAccess.Write, FileShare.Read); lib.WriteJson(fs); fs.Close(); - var lambdas = CreateElmApi().ProcessLibrary(lib); + var lambdas = ToFluentElmToolkit().ProcessLibrary(lib); _ = lambdas.CompileAll(); } [TestMethod] public void FHIRHelpers_ToConcept_Right_Types() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library FHIRHelpers version '4.0.1' using FHIR version '4.0.1' @@ -55,7 +55,7 @@ define function ToConcept(concept FHIR.CodeableConcept): [TestMethod] public void FHIRHelpers_ToConcept_Query() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library FHIRHelpers version '4.0.1' using FHIR version '4.0.1' @@ -82,15 +82,15 @@ define function ToConcept(concept FHIR.CodeableConcept): lib.statements.Should().HaveCount(2); var fd = lib.statements[1].Should().BeOfType().Subject; - var lambdas = CreateElmApi().ProcessLibrary(lib); + var lambdas = ToFluentElmToolkit().ProcessLibrary(lib); _ = lambdas.CompileAll(); } [TestMethod] public void FHIRHelpers_Coding_To_ListCodes() { - var cqlApi = CreateCqlApi().AddFHIRHelpers(); - var lib = cqlApi.MakeLibrary(""" + var cqlToolkit = CreateFluentCqlToolkit().AddFHIRHelpers(); + var lib = cqlToolkit.MakeLibrary(""" library Test version '1.0.0' using FHIR version '4.0.1' diff --git a/Cql/CqlToElmTests/FilesTest.cs b/Cql/CqlToElmTests/(tests)/FilesTest.cs similarity index 100% rename from Cql/CqlToElmTests/FilesTest.cs rename to Cql/CqlToElmTests/(tests)/FilesTest.cs diff --git a/Cql/CqlToElmTests/FlattenTest.cs b/Cql/CqlToElmTests/(tests)/FlattenTest.cs similarity index 82% rename from Cql/CqlToElmTests/FlattenTest.cs rename to Cql/CqlToElmTests/(tests)/FlattenTest.cs index 3d1c1e53f..7ad084ac8 100644 --- a/Cql/CqlToElmTests/FlattenTest.cs +++ b/Cql/CqlToElmTests/(tests)/FlattenTest.cs @@ -8,7 +8,7 @@ public class FlattenTest : Base [TestMethod] public void FlattenEmpty() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ListTest version '1.0.0' define private FlattenEmpty: Flatten({{},{}}) @@ -26,7 +26,7 @@ library ListTest version '1.0.0' [TestMethod] public void FlattenCapitalF() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ListTest version '1.0.0' define private FlattenEmpty: Flatten({{},{}}) @@ -36,11 +36,11 @@ library ListTest version '1.0.0' [TestMethod] public void FlattenListNullAndNull() { - var lib = CreateCqlApi().MakeLibraryFromExpression("Flatten({{null}, {null}})"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("Flatten({{null}, {null}})"); var flatten = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run>(flatten, lib); // {null, null} result!.Count.Should().Be(2); - var equal = CreateCqlApi().MakeLibraryFromExpression("Flatten({{null}, {null}}) = {null, null}") + var equal = CreateFluentCqlToolkit().MakeLibraryFromExpression("Flatten({{null}, {null}}) = {null, null}") .Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var eqr = Run(equal, lib); // {null, null} eqr.Should().BeTrue(); @@ -48,7 +48,7 @@ public void FlattenListNullAndNull() [TestMethod] public void FlattenListOfValueSet() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library FlattenValueSets version '1.0.0' valueset "One": 'https://hl7.org/one' @@ -64,7 +64,7 @@ library FlattenValueSets version '1.0.0' [TestMethod] public void FlattenChoiceType() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ListTest version '1.0.0' define choice: @@ -84,8 +84,8 @@ library ListTest version '1.0.0' public void FlattenMixedChoiceType() { // requires list promotion - var cqlApi = CreateCqlApi(); - var library = cqlApi.MakeLibrary( """ + var cqlToolkit = CreateFluentCqlToolkit(); + var library = cqlToolkit.MakeLibrary( """ library Test version '1.0.0' using FHIR version '4.0.1' @@ -95,8 +95,8 @@ library Test version '1.0.0' """, "Could not resolve call to operator Flatten with signature (List>>)."); // no errors - cqlApi = CreateCqlApi(EnableListPromotion:true); - library = cqlApi.MakeLibrary(""" + cqlToolkit = CreateFluentCqlToolkit(EnableListPromotion:true); + library = cqlToolkit.MakeLibrary(""" library Test version '1.0.0' using FHIR version '4.0.1' diff --git a/Cql/CqlToElmTests/FunctionDefinitionBuilderTest.cs b/Cql/CqlToElmTests/(tests)/FunctionDefinitionBuilderTest.cs similarity index 100% rename from Cql/CqlToElmTests/FunctionDefinitionBuilderTest.cs rename to Cql/CqlToElmTests/(tests)/FunctionDefinitionBuilderTest.cs diff --git a/Cql/CqlToElmTests/FunctionDefinitionTest.cs b/Cql/CqlToElmTests/(tests)/FunctionDefinitionTest.cs similarity index 88% rename from Cql/CqlToElmTests/FunctionDefinitionTest.cs rename to Cql/CqlToElmTests/(tests)/FunctionDefinitionTest.cs index f6cf5826a..5b757e7e6 100644 --- a/Cql/CqlToElmTests/FunctionDefinitionTest.cs +++ b/Cql/CqlToElmTests/(tests)/FunctionDefinitionTest.cs @@ -1,5 +1,6 @@ +using CqlSdkPrototype.Elm.Fluent.Extensions; using CqlSdkPrototype.Infrastructure; -using CqlSdkPrototype.Runtime.Extensions; +using CqlSdkPrototype.Invocation.Fluent.Extensions; using Hl7.Cql.Elm; using Hl7.Cql.Runtime; @@ -14,7 +15,7 @@ private FunctionDef shouldDefineFunction(Library l, string name) => [TestMethod] public void DefinePrivateFluentFunction() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library FuncTest version '1.0.0' using FHIR version '4.0.1' context Patient @@ -31,7 +32,7 @@ define private fluent function Two(): 2 [TestMethod] public void DefinePublicNonFluentExternalFunction() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library FuncTest version '1.0.0' define public function Ext() returns String: external """); @@ -45,7 +46,7 @@ define public function Ext() returns String: external [TestMethod] public void UntypedFunctionsAreIllegal() { - _ = CreateCqlApi().MakeLibrary(""" + _ = CreateFluentCqlToolkit().MakeLibrary(""" library FuncTest version '1.0.0' define public function Ext(): external """, @@ -56,7 +57,7 @@ define public function Ext(): external [TestMethod] public void OptionalReturnTypesMayBeTheSame() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library FuncTest version '1.0.0' define function Two() returns Integer: 2 """); @@ -68,7 +69,7 @@ define function Two() returns Integer: 2 [TestMethod] public void OptionalReturnTypesMayBeSupertype() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library FuncTest version '1.0.0' define function Two() returns Any: 2 """); @@ -80,7 +81,7 @@ define function Two() returns Any: 2 [TestMethod] public void MakesParametersVisibleInScope() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library FuncTest version '1.0.0' define function Double(a Integer): a*2 """); @@ -94,7 +95,7 @@ define function Double(a Integer): a*2 [TestMethod] public void SignalsUnknownParameters() { - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library FuncTest version '1.0.0' define function Double(a Integer): b """, @@ -104,7 +105,7 @@ define function Double(a Integer): b [TestMethod] public void ResolvesInParentScope() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library FuncTest version '1.0.0' define b: 5 define function Double(a Integer): b @@ -120,7 +121,7 @@ define function Double(a Integer): b [TestMethod] public void ResolvesNearestScope() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library FuncTest version '1.0.0' define a: 5 define function Replace(a String): a @@ -134,7 +135,7 @@ define function Replace(a String): a [TestMethod] public void DoesForwardsReference() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library FuncTest version '1.0.0' define b: a define a: 5 @@ -148,7 +149,7 @@ library FuncTest version '1.0.0' [TestMethod] public void DetectsCycle() { - _ = CreateCqlApi().MakeLibrary(""" + _ = CreateFluentCqlToolkit().MakeLibrary(""" library FuncTest version '1.0.0' define a: b define b: a @@ -159,7 +160,7 @@ library FuncTest version '1.0.0' [TestMethod] public void CallsFluentOnMember() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library FuncTest version '1.0.0' using FHIR version '4.0.1' @@ -177,8 +178,8 @@ library FuncTest version '1.0.0' [TestMethod] public void CallsFluentOnMember_AcrossLibrary() { - var cqlApi = CreateCqlApi(); - var fluentLib = cqlApi.MakeLibrary(""" + var cqlToolkit = CreateFluentCqlToolkit(); + var fluentLib = cqlToolkit.MakeLibrary(""" library FluentLib version '1.0.0' using FHIR version '4.0.1' @@ -187,7 +188,7 @@ library FluentLib version '1.0.0' Interval[date from start of period, date from end of period] """); - var testLib = cqlApi.MakeLibrary(""" + var testLib = cqlToolkit.MakeLibrary(""" library FuncTest version '1.0.0' using FHIR version '4.0.1' @@ -206,8 +207,8 @@ include FluentLib version '1.0.0' [TestMethod] public void BirthdatePlusAge() { - var cqlApi = CreateCqlApi().AddFHIRHelpers();; - var lib = cqlApi.MakeLibrary(""" + var cqlToolkit = CreateFluentCqlToolkit().AddFHIRHelpers();; + var lib = cqlToolkit.MakeLibrary(""" library Test version '1.0.0' using FHIR version '4.0.1' @@ -234,7 +235,7 @@ define function f(patient FHIR.Patient, condition FHIR.Condition): [TestMethod] public void ComplexCaseStatement() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library FuncTest version '1.0.0' using FHIR version '4.0.1' @@ -262,7 +263,7 @@ when condition.onset is Range and birthDate is not null then [TestMethod] public void External_Function() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library FuncTest version '1.0.0' define function Add(left Integer, right Integer) returns Integer: external @@ -277,7 +278,7 @@ define function Add(left Integer, right Integer) returns Integer: external [TestMethod] public void CSharp_Keyword_Parameter_Name() { - var cqlApi = CreateCqlApi(); + var cqlToolkit = CreateFluentCqlToolkit(); var cqlLibraryString = CqlLibraryString.Parse( """ library FuncTest version '1.0.0' @@ -285,14 +286,18 @@ library FuncTest version '1.0.0' define function ToInteger(decimal System.Decimal) returns System.Integer: external """); - var lib = cqlApi.MakeLibrary(cqlLibraryString.Cql); - var lambdas = cqlApi.CreateElmApi().ProcessLibrary(lib); + var lib = cqlToolkit.MakeLibrary(cqlLibraryString.Cql); + var lambdas = cqlToolkit.ToFluentElmToolkit().ProcessLibrary(lib); var expr = lambdas["FuncTest-1.0.0", "ToInteger", typeof(CqlContext), typeof(decimal?)]; expr.Parameters.Should().HaveCount(2); expr.Parameters[1].Name.Should().Be("decimal"); - using var scope = cqlApi.CreateRuntimeScope(); - _ = scope; + var act = () => + { + using var librarySetInvoker = cqlToolkit.ToLibrarySetInvoker(); + _ = librarySetInvoker; + }; + act.Should().NotThrow(); } } } \ No newline at end of file diff --git a/Cql/CqlToElmTests/GreaterTest.cs b/Cql/CqlToElmTests/(tests)/GreaterTest.cs similarity index 95% rename from Cql/CqlToElmTests/GreaterTest.cs rename to Cql/CqlToElmTests/(tests)/GreaterTest.cs index e7887ed8b..96ea444dd 100644 --- a/Cql/CqlToElmTests/GreaterTest.cs +++ b/Cql/CqlToElmTests/(tests)/GreaterTest.cs @@ -11,7 +11,7 @@ public class GreaterTest : Base [TestMethod] public void Integer_GreaterThan_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_GreaterThan_Integer: 1 > -1 @@ -56,7 +56,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -67,7 +67,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_GreaterThan_Integer_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_GreaterThan_Integer_False: 1 > 2 @@ -112,7 +112,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -123,7 +123,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_GreaterThan_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_GreaterThan_Long: 10 > 1L @@ -168,7 +168,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -179,7 +179,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_GreaterThan_Decimal_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_GreaterThan_Decimal_False: -10 > 1.01 @@ -224,7 +224,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -236,7 +236,7 @@ library EqualsTest version '1.0.0' public void Integer_GreaterThan_Quantity() { // 1 converts to 1.0 '1' and '1' units are greater to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_GreaterThan_Quantity: 2 > 1.0 'g' @@ -281,7 +281,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -292,7 +292,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_GreaterThan_Quantity_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_GreaterThan_Quantity_False: 0 > 1.01 '1' @@ -337,7 +337,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -348,7 +348,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_GreaterThan_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_GreaterThan_Null: 1 > null @@ -393,7 +393,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -403,7 +403,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Null_GreaterThan_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Null_GreaterThan_Integer: null > 1 @@ -448,7 +448,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -462,7 +462,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_GreaterThan_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_GreaterThan_Long: 1L > -1L @@ -507,7 +507,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -518,7 +518,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_GreaterThan_Long_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_GreaterThan_Long_False: 1L > 2L @@ -563,7 +563,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -574,7 +574,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_GreaterThan_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_GreaterThan_Long: 1L > 0 @@ -619,7 +619,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -630,7 +630,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_GreaterThan_Decimal_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_NotGreaterThan_Decimal: 1L > 1.01 @@ -675,7 +675,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -687,7 +687,7 @@ library EqualsTest version '1.0.0' public void Long_GreaterThan_Quantity() { // 1L converts to 1.0 '1' and '1' units are greater to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_GreaterThan_Quantity: 10L > 1.0 'g' @@ -732,7 +732,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -743,7 +743,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_NotGreaterThan_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_NotGreaterThan_Quantity: 1L > 1.01 '1' @@ -788,7 +788,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -799,7 +799,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_GreaterThan_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_GreaterThan_Null: 1L > null @@ -844,7 +844,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -854,7 +854,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Null_GreaterThan_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Null_GreaterThan_Long: null > 1L @@ -899,7 +899,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -913,7 +913,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_GreaterThan_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_GreaterThan_Decimal: 1.00001 > 1.0 @@ -958,7 +958,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -969,7 +969,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_GreaterThan_Decimal_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_GreaterThan_Decimal_False: 1.0 > 2.0 @@ -1014,7 +1014,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1025,7 +1025,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_GreaterThan_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_GreaterThan_Decimal: 1.01 > 1 @@ -1070,7 +1070,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1081,7 +1081,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_GreaterThan_Long_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_NotGreaterThan_Decimal: 2.0 > 10L @@ -1126,7 +1126,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1138,7 +1138,7 @@ library EqualsTest version '1.0.0' public void Decimal_GreaterThan_Quantity() { // 1.0 converts to 1.0 '1' and '1' units are greater to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_GreaterThan_Quantity: 2.0 > 1.0 'g' @@ -1183,7 +1183,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1194,7 +1194,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_GreaterThan_Quantity_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_GreaterThan_Quantity_False: 1.0 > 1.01 '1' @@ -1239,7 +1239,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1250,7 +1250,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_GreaterThan_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_GreaterThan_Null: 1.0 > null @@ -1295,7 +1295,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -1305,7 +1305,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Null_GreaterThan_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Null_GreaterThan_Decimal: null > 1.0 @@ -1350,7 +1350,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -1364,7 +1364,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_GreaterThan_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_GreaterThan_Quantity: 1.1 '1' > 1.0 '1' @@ -1409,7 +1409,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1420,7 +1420,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_GreaterThan_Quantity_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_GreaterThan_Quantity_False: 1.0 '1' > 2.0 '1' @@ -1465,7 +1465,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1476,7 +1476,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_GreaterThan_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_GreaterThan_Quantity: 1000.0 '1' > 1 @@ -1521,7 +1521,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1532,7 +1532,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_GreaterThan_Long_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_NotGreaterThan_Quantity: 2.0 '1' > 10L @@ -1577,7 +1577,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1589,7 +1589,7 @@ library EqualsTest version '1.0.0' public void Quantity_GreaterThan_Decimal() { // 1.0 converts to 1.0 '1' and '1' units are greater to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_GreaterThan_Decimal: 1.0 'g' > 0.1 @@ -1634,7 +1634,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1645,7 +1645,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_GreaterThan_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_GreaterThan_Null: 1.0 '1' > null @@ -1690,7 +1690,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -1700,7 +1700,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Null_GreaterThan_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Null_GreaterThan_Integer: null > 1.0 '1' @@ -1745,7 +1745,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -1758,7 +1758,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Date_GreaterThan_Date() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Date_GreaterThan_Date: @2023-12-31 > @2023-01-01 @@ -1803,7 +1803,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Date", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1814,7 +1814,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Date_GreaterThan_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private String_GreaterThan_String: @2023 > null @@ -1859,7 +1859,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Date", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -1869,7 +1869,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Null_GreaterThan_Date() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Null_GreaterThan_Date: null > @2023 @@ -1914,7 +1914,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Date", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(greater); + var lambda = ToFluentElmToolkit().Lambda(greater); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); diff --git a/Cql/CqlToElmTests/IfThenElseTest.cs b/Cql/CqlToElmTests/(tests)/IfThenElseTest.cs similarity index 81% rename from Cql/CqlToElmTests/IfThenElseTest.cs rename to Cql/CqlToElmTests/(tests)/IfThenElseTest.cs index 6580fac69..68cb4ae3b 100644 --- a/Cql/CqlToElmTests/IfThenElseTest.cs +++ b/Cql/CqlToElmTests/(tests)/IfThenElseTest.cs @@ -1,4 +1,3 @@ -using CqlSdkPrototype.Cql.Internal; using Hl7.Cql.Elm; namespace Hl7.Cql.CqlToElm.Test @@ -10,7 +9,7 @@ public class IfThenElseTest : Base [TestMethod] public void True_Integer_Integer() { - var library = CreateCqlApi().MakeLibraryFromExpression("if true then 4 else 5"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("if true then 4 else 5"); var ifThenElse = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); ifThenElse.condition.Should().BeLiteralBool(true); @@ -23,7 +22,7 @@ public void True_Integer_Integer() [TestMethod] public void True_Integer_Decimal() { - var library = CreateCqlApi().MakeLibraryFromExpression("if true then 4 else 5.0"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("if true then 4 else 5.0"); var ifThenElse = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); ifThenElse.condition.Should().BeLiteralBool(true); @@ -38,7 +37,7 @@ public void True_Integer_Decimal() [TestMethod] public void True_Decimal_Integer() { - var library = CreateCqlApi().MakeLibraryFromExpression("if false then 4.0 else 5"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("if false then 4.0 else 5"); var ifThenElse = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); ifThenElse.condition.Should().BeLiteralBool(false); @@ -53,7 +52,7 @@ public void True_Decimal_Integer() [TestMethod] public void True_Decimal_String() { - var library = CreateCqlApi().MakeLibraryFromExpression("if false then 4.0 else 'hello'"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("if false then 4.0 else 'hello'"); var ifThenElse = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var expectedType = new ChoiceTypeSpecifier(SystemTypes.DecimalType, SystemTypes.StringType); @@ -75,9 +74,10 @@ public void True_Decimal_String() [TestMethod] public void String_Integer_Integer() { - var messageProvider = CreateCqlApi().AsInternal().Services.ServiceProvider.GetRequiredService(); + var fluentCqlToolkit = CreateFluentCqlToolkit(); + var messageProvider = fluentCqlToolkit.GetMessageProvider(); string[] expectedErrors = [messageProvider.TypeFoundIsNotExpected(SystemTypes.StringType, SystemTypes.BooleanType)]; - var library = CreateCqlApi().MakeLibraryFromExpression("if 'hello' then 4 else 5", expectedErrors); + var library = fluentCqlToolkit.MakeLibraryFromExpression("if 'hello' then 4 else 5", expectedErrors); var @if = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); @if.resultTypeSpecifier.Should().Be(SystemTypes.IntegerType); diff --git a/Cql/CqlToElmTests/ImpliesTest.cs b/Cql/CqlToElmTests/(tests)/ImpliesTest.cs similarity index 95% rename from Cql/CqlToElmTests/ImpliesTest.cs rename to Cql/CqlToElmTests/(tests)/ImpliesTest.cs index 421994ec7..3be3e75df 100644 --- a/Cql/CqlToElmTests/ImpliesTest.cs +++ b/Cql/CqlToElmTests/(tests)/ImpliesTest.cs @@ -9,7 +9,7 @@ public class ImpliesTest : Base [TestMethod] public void True_Implies_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ImpliesTest version '1.0.0' define private True_Implies_False: true implies false @@ -54,7 +54,7 @@ library ImpliesTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(implies); + var lambda = ToFluentElmToolkit().Lambda(implies); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -65,7 +65,7 @@ library ImpliesTest version '1.0.0' [TestMethod] public void True_Implies_True() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ImpliesTest version '1.0.0' define private True_Implies_True: true implies true @@ -110,7 +110,7 @@ library ImpliesTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(implies); + var lambda = ToFluentElmToolkit().Lambda(implies); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -121,7 +121,7 @@ library ImpliesTest version '1.0.0' [TestMethod] public void False_Implies_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ImpliesTest version '1.0.0' define private False_Implies_False: false implies false @@ -166,7 +166,7 @@ library ImpliesTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(implies); + var lambda = ToFluentElmToolkit().Lambda(implies); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -177,7 +177,7 @@ library ImpliesTest version '1.0.0' [TestMethod] public void True_Implies_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ImpliesTest version '1.0.0' define private True_Implies_Null: true implies null @@ -222,7 +222,7 @@ library ImpliesTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(implies); + var lambda = ToFluentElmToolkit().Lambda(implies); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -232,7 +232,7 @@ library ImpliesTest version '1.0.0' [TestMethod] public void Null_Implies_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ImpliesTest version '1.0.0' define private Null_Implies_False: null implies false @@ -277,7 +277,7 @@ library ImpliesTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(implies); + var lambda = ToFluentElmToolkit().Lambda(implies); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -287,7 +287,7 @@ library ImpliesTest version '1.0.0' [TestMethod] public void Null_Implies_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ImpliesTest version '1.0.0' define private Null_Implies_Null: null implies null @@ -332,7 +332,7 @@ library ImpliesTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(implies); + var lambda = ToFluentElmToolkit().Lambda(implies); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -342,7 +342,7 @@ library ImpliesTest version '1.0.0' [TestMethod] public void True_Implies_1() { - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library ImpliesTest version '1.0.0' define private True_Implies_1: true implies 1 diff --git a/Cql/CqlToElmTests/InTest.cs b/Cql/CqlToElmTests/(tests)/InTest.cs similarity index 86% rename from Cql/CqlToElmTests/InTest.cs rename to Cql/CqlToElmTests/(tests)/InTest.cs index a8064392f..508e657ec 100644 --- a/Cql/CqlToElmTests/InTest.cs +++ b/Cql/CqlToElmTests/(tests)/InTest.cs @@ -8,7 +8,7 @@ public class InTest : Base [TestMethod] public void Starts_Properly_Within_Start() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library InTest version '1.0.0' define private Starts_Properly_Within_Start: Interval[@2023, @2030] starts properly within 1 year of start Interval[@2022, @2030] @@ -37,7 +37,7 @@ library InTest version '1.0.0' [TestMethod] public void Starts_Within_Start() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library InTest version '1.0.0' define f: Interval[@2023, @2030] starts within 1 year of start Interval[@2022, @2030] @@ -49,7 +49,7 @@ library InTest version '1.0.0' [TestMethod] public void Properly_Within_Start() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library InTest version '1.0.0' define private Properly_Within_Start: Interval[@2023, @2030] properly within 1 year of start Interval[@2022, @2030] @@ -60,7 +60,7 @@ library InTest version '1.0.0' [TestMethod] public void TestInNullBoundaries() { - var lib = CreateCqlApi().MakeLibraryFromExpression("5 in Interval[null as Integer, null as Integer]"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("5 in Interval[null as Integer, null as Integer]"); var @in = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(@in, lib); Assert.IsFalse(result); @@ -68,14 +68,14 @@ public void TestInNullBoundaries() public void NullContains5() { - var lib = CreateCqlApi().MakeLibraryFromExpression("null contains 5"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("null contains 5"); var @in = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); } [TestMethod] public void Starts_Within_PointInterval() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library InTest version '1.0.0' define f: diff --git a/Cql/CqlToElmTests/IncludedInTest.cs b/Cql/CqlToElmTests/(tests)/IncludedInTest.cs similarity index 95% rename from Cql/CqlToElmTests/IncludedInTest.cs rename to Cql/CqlToElmTests/(tests)/IncludedInTest.cs index 1094b8f1a..4d0758044 100644 --- a/Cql/CqlToElmTests/IncludedInTest.cs +++ b/Cql/CqlToElmTests/(tests)/IncludedInTest.cs @@ -9,7 +9,7 @@ public class IncludedInTest : Base [TestMethod] public void Starts_Properly_During_Year() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludedInTest version '1.0.0' define private Starts_Properly_During_Year: Interval[@2023, @2030] starts properly during year of Interval[@2020, @2030] @@ -37,7 +37,7 @@ library IncludedInTest version '1.0.0' [TestMethod] public void Starts_Properly_IncludedIn_Year() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludedInTest version '1.0.0' define private Starts_Properly_IncludedIn_Year: Interval[@2023, @2030] starts properly included in year of Interval[@2020, @2030] @@ -66,7 +66,7 @@ library IncludedInTest version '1.0.0' [TestMethod] public void Starts_During_Year() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludedInTest version '1.0.0' define private Starts_During_Year: Interval[@2023, @2030] starts during year of Interval[@2020, @2030] @@ -95,7 +95,7 @@ library IncludedInTest version '1.0.0' [TestMethod] public void Starts_IncludedIn_Year() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludedInTest version '1.0.0' define private Starts_During_Year: Interval[@2023, @2030] starts included in year of Interval[@2020, @2030] @@ -124,7 +124,7 @@ library IncludedInTest version '1.0.0' [TestMethod] public void Properly_During_Year() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludedInTest version '1.0.0' define private Starts_Properly_During_Year: Interval[@2023, @2030] properly during year of Interval[@2020, @2030] @@ -153,7 +153,7 @@ library IncludedInTest version '1.0.0' [TestMethod] public void Properly_IncludedIn_Year() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludedInTest version '1.0.0' define private Properly_IncludedIn_Year: Interval[@2023, @2030] properly included in year of Interval[@2020, @2030] @@ -182,7 +182,7 @@ library IncludedInTest version '1.0.0' [TestMethod] public void During_Year() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludedInTest version '1.0.0' define private Starts_During_Year: Interval[@2023, @2030] during year of Interval[@2020, @2030] @@ -211,7 +211,7 @@ library IncludedInTest version '1.0.0' [TestMethod] public void IncludedIn_Year() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludedInTest version '1.0.0' define private IncludedIn_Year: Interval[@2023, @2030] included in year of Interval[@2020, @2030] @@ -240,7 +240,7 @@ library IncludedInTest version '1.0.0' [TestMethod] public void Properly_During() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludedInTest version '1.0.0' define private Properly_During: Interval[@2023, @2030] properly during Interval[@2020, @2031] @@ -269,7 +269,7 @@ library IncludedInTest version '1.0.0' [TestMethod] public void Properly_IncludedIn() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludedInTest version '1.0.0' define private Properly_IncludedIn: Interval[@2023, @2030] properly included in Interval[@2020, @2031] @@ -298,7 +298,7 @@ library IncludedInTest version '1.0.0' [TestMethod] public void Starts_During() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludedInTest version '1.0.0' define private Starts_During: Interval[@2023, @2030] starts during Interval[@2020, @2030] @@ -327,7 +327,7 @@ library IncludedInTest version '1.0.0' [TestMethod] public void Starts_IncludedIn() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludedInTest version '1.0.0' define private Starts_During: Interval[@2023, @2030] starts included in Interval[@2020, @2030] @@ -356,7 +356,7 @@ library IncludedInTest version '1.0.0' [TestMethod] public void Starts_Properly_During() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludedInTest version '1.0.0' define private Starts_Properly_During_Year: Interval[@2023, @2030] starts properly during Interval[@2020, @2030] @@ -384,7 +384,7 @@ library IncludedInTest version '1.0.0' [TestMethod] public void Starts_Properly_IncludedIn() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludedInTest version '1.0.0' define private Starts_Properly_IncludedIn: Interval[@2023, @2030] starts properly included in Interval[@2020, @2030] diff --git a/Cql/CqlToElmTests/IncludesTest.cs b/Cql/CqlToElmTests/(tests)/IncludesTest.cs similarity index 94% rename from Cql/CqlToElmTests/IncludesTest.cs rename to Cql/CqlToElmTests/(tests)/IncludesTest.cs index 1318b0582..5038be971 100644 --- a/Cql/CqlToElmTests/IncludesTest.cs +++ b/Cql/CqlToElmTests/(tests)/IncludesTest.cs @@ -8,7 +8,7 @@ public class IncludesTest : Base [TestMethod] public void Proper_Includes_Day_Start() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Proper_Includes_Day_Start: Interval[@2023-01-01, @2023-06-30] properly includes day of start Interval[@2023-04-01, @2023-04-30] @@ -36,7 +36,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Proper_Includes_Day_End() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Proper_Includes_Day_End: Interval[@2023-01-01, @2023-06-30] properly includes day of end Interval[@2023-04-01, @2023-04-30] @@ -64,7 +64,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Proper_Includes_Year() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Proper_Includes_Day_Start: Interval[@2023, @2023] properly includes year of Interval[@2023, @2023] @@ -92,7 +92,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Proper_Includes() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Proper_Includes: Interval[@2023, @2023] properly includes Interval[@2023, @2023] @@ -120,7 +120,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Includes_Day_Start() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Includes_Day_Start: Interval[@2023-01-01, @2023-06-30] includes day of start Interval[@2023-04-01, @2023-04-30] @@ -148,7 +148,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Includes_Day_End() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Includes_Day_End: Interval[@2023-01-01, @2023-06-30] includes day of end Interval[@2023-04-01, @2023-04-30] @@ -176,7 +176,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Includes_Year() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Proper_Includes_Day_Start: Interval[@2023, @2023] includes year of Interval[@2023, @2023] @@ -204,7 +204,7 @@ library ConcurrentWithTest version '1.0.0' [TestMethod] public void Includes() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ConcurrentWithTest version '1.0.0' define private Includes: Interval[@2023, @2023] includes Interval[@2023, @2023] @@ -234,7 +234,7 @@ public void EmptyList_Includes_EmptyList() { // Declare the cost of casting to Any to be higher than an exact match // that should make these unambiguous - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludesTest version '1.0.0' define private EmptyList_Includes_EmptyList: {} includes {} @@ -245,7 +245,7 @@ library IncludesTest version '1.0.0' [TestMethod] public void NullBoundariesProperlyIncludesIntegerInterval() { - var library = CreateCqlApi().MakeLibraryFromExpression("Interval[null as Integer, null as Integer] properly includes Interval[1, 10]"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("Interval[null as Integer, null as Integer] properly includes Interval[1, 10]"); var intersect = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(intersect, library); result.Should().BeNull(); diff --git a/Cql/CqlToElmTests/IndexTest.cs b/Cql/CqlToElmTests/(tests)/IndexTest.cs similarity index 75% rename from Cql/CqlToElmTests/IndexTest.cs rename to Cql/CqlToElmTests/(tests)/IndexTest.cs index 8432a7362..5e5afc4b8 100644 --- a/Cql/CqlToElmTests/IndexTest.cs +++ b/Cql/CqlToElmTests/(tests)/IndexTest.cs @@ -8,7 +8,7 @@ public class IndexTest : Base [TestMethod] public void LastIndexOf() { - var lib = CreateCqlApi().MakeLibraryFromExpression("LastPositionOf('hi', 'Ohio is the place to be!')"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("LastPositionOf('hi', 'Ohio is the place to be!')"); var lpo = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(lpo, lib); result.Should().Be(1); diff --git a/Cql/CqlToElmTests/InfixSetTest.cs b/Cql/CqlToElmTests/(tests)/InfixSetTest.cs similarity index 81% rename from Cql/CqlToElmTests/InfixSetTest.cs rename to Cql/CqlToElmTests/(tests)/InfixSetTest.cs index 416ec9bb7..c7632aa8f 100644 --- a/Cql/CqlToElmTests/InfixSetTest.cs +++ b/Cql/CqlToElmTests/(tests)/InfixSetTest.cs @@ -9,7 +9,7 @@ public class InfixSetTest : Base [TestMethod] public void Interval_Except() { - var library = CreateCqlApi().MakeLibraryFromExpression("Interval[1, 10] except Interval[4, 10]"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("Interval[1, 10] except Interval[4, 10]"); var except = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run>(except, library); result.Should().NotBeNull(); @@ -22,7 +22,7 @@ public void Interval_Except() [TestMethod] public void Interval_Union() { - var library = CreateCqlApi().MakeLibraryFromExpression("Interval[1, 10] union Interval[4, 15]"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("Interval[1, 10] union Interval[4, 15]"); var union = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run>(union, library); result.Should().NotBeNull(); @@ -34,7 +34,7 @@ public void Interval_Union() [TestMethod] public void Interval_Union_Pipe_Operator() { - var library = CreateCqlApi().MakeLibraryFromExpression("Interval[1, 10] | Interval[4, 15]"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("Interval[1, 10] | Interval[4, 15]"); var union = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run>(union, library); result.Should().NotBeNull(); @@ -47,7 +47,7 @@ public void Interval_Union_Pipe_Operator() [TestMethod] public void Interval_Intersect_Operator() { - var library = CreateCqlApi().MakeLibraryFromExpression("Interval[1, 5] intersect Interval[3, 7]"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("Interval[1, 5] intersect Interval[3, 7]"); var intersect = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run>(intersect, library); result.Should().NotBeNull(); diff --git a/Cql/CqlToElmTests/InstanceTest.cs b/Cql/CqlToElmTests/(tests)/InstanceTest.cs similarity index 95% rename from Cql/CqlToElmTests/InstanceTest.cs rename to Cql/CqlToElmTests/(tests)/InstanceTest.cs index 7d9055505..0332982ff 100644 --- a/Cql/CqlToElmTests/InstanceTest.cs +++ b/Cql/CqlToElmTests/(tests)/InstanceTest.cs @@ -9,7 +9,7 @@ public class InstanceTest : Base [TestMethod] public void Concept_Instance() { - var library = CreateCqlApi( + var library = CreateFluentCqlToolkit( EnableListDemotion:true, EnableListPromotion:true, EnableIntervalDemotion: true, diff --git a/Cql/CqlToElmTests/IntervalTest.cs b/Cql/CqlToElmTests/(tests)/IntervalTest.cs similarity index 91% rename from Cql/CqlToElmTests/IntervalTest.cs rename to Cql/CqlToElmTests/(tests)/IntervalTest.cs index 2163e3894..275be27f5 100644 --- a/Cql/CqlToElmTests/IntervalTest.cs +++ b/Cql/CqlToElmTests/(tests)/IntervalTest.cs @@ -10,7 +10,7 @@ public class IntervalTest : Base [TestMethod] public void Interval_InvalidType() { - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library IntervalTest version '1.0.0' define private Interval_InvalidType: Interval[{},{}] @@ -20,7 +20,7 @@ library IntervalTest version '1.0.0' [TestMethod] public void Interval_Quantity_Incompatible_Units() { - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library IntervalTest version '1.0.0' define private Interval_InvalidType: Interval[100 'a', 200 'kg'] @@ -30,7 +30,7 @@ library IntervalTest version '1.0.0' [TestMethod] public void Interval_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IntervalTest version '1.0.0' define private Interval_Integer: Interval[1,2] @@ -52,7 +52,7 @@ library IntervalTest version '1.0.0' Assert.IsNotNull(nts.name?.Name); Assert.AreEqual($"{{{SystemUri}}}Integer", nts.name?.Name); - var lambda = CreateElmApi().Lambda(interval); + var lambda = ToFluentElmToolkit().Lambda(interval); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -68,7 +68,7 @@ library IntervalTest version '1.0.0' [TestMethod] public void Interval_Integer_Null_High() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IntervalTest version '1.0.0' define private Interval_Integer: Interval[1,null) @@ -90,7 +90,7 @@ library IntervalTest version '1.0.0' Assert.IsNotNull(nts.name?.Name); Assert.AreEqual($"{{{SystemUri}}}Integer", nts.name?.Name); - var lambda = CreateElmApi().Lambda(interval); + var lambda = ToFluentElmToolkit().Lambda(interval); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -106,7 +106,7 @@ library IntervalTest version '1.0.0' [TestMethod] public void Interval_Integer_Null_Low() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IntervalTest version '1.0.0' define private Interval_Integer: Interval[null, 1) @@ -128,7 +128,7 @@ library IntervalTest version '1.0.0' Assert.IsNotNull(nts.name?.Name); Assert.AreEqual($"{{{SystemUri}}}Integer", nts.name?.Name); - var lambda = CreateElmApi().Lambda(interval); + var lambda = ToFluentElmToolkit().Lambda(interval); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -144,7 +144,7 @@ library IntervalTest version '1.0.0' [TestMethod] public void Interval_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IntervalTest version '1.0.0' define private Interval_Long: Interval(-100L,20L] @@ -166,7 +166,7 @@ library IntervalTest version '1.0.0' Assert.IsNotNull(nts.name?.Name); Assert.AreEqual($"{{{SystemUri}}}Long", nts.name?.Name); - var lambda = CreateElmApi().Lambda(interval); + var lambda = ToFluentElmToolkit().Lambda(interval); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -182,7 +182,7 @@ library IntervalTest version '1.0.0' [TestMethod] public void Interval_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IntervalTest version '1.0.0' define private Interval_Decimal: Interval[-0.00000001, 0.0) @@ -204,7 +204,7 @@ library IntervalTest version '1.0.0' Assert.IsNotNull(nts.name?.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", nts.name?.Name); - var lambda = CreateElmApi().Lambda(interval); + var lambda = ToFluentElmToolkit().Lambda(interval); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -220,7 +220,7 @@ library IntervalTest version '1.0.0' [TestMethod] public void Interval_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IntervalTest version '1.0.0' define private Interval_Decimal: Interval(100 '1', 200 '1') @@ -242,7 +242,7 @@ library IntervalTest version '1.0.0' Assert.IsNotNull(nts.name?.Name); Assert.AreEqual($"{{{SystemUri}}}Quantity", nts.name?.Name); - var lambda = CreateElmApi().Lambda(interval); + var lambda = ToFluentElmToolkit().Lambda(interval); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -258,7 +258,7 @@ library IntervalTest version '1.0.0' [TestMethod] public void Interval_Date() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IntervalTest version '1.0.0' define private Interval_Date: Interval[@2023-01-01, @2023-12-31] @@ -280,7 +280,7 @@ library IntervalTest version '1.0.0' Assert.IsNotNull(nts.name?.Name); Assert.AreEqual($"{{{SystemUri}}}Date", nts.name?.Name); - var lambda = CreateElmApi().Lambda(interval); + var lambda = ToFluentElmToolkit().Lambda(interval); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -296,7 +296,7 @@ library IntervalTest version '1.0.0' [TestMethod] public void Interval_DateTime() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IntervalTest version '1.0.0' define private Interval_DateTime: Interval[@2023-01-01T00:00:00.000Z, @2023-12-31T23:59:59.999Z] @@ -318,7 +318,7 @@ library IntervalTest version '1.0.0' Assert.IsNotNull(nts.name?.Name); Assert.AreEqual($"{{{SystemUri}}}DateTime", nts.name?.Name); - var lambda = CreateElmApi().Lambda(interval); + var lambda = ToFluentElmToolkit().Lambda(interval); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -335,7 +335,7 @@ library IntervalTest version '1.0.0' [TestMethod] public void Interval_Time() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IntervalTest version '1.0.0' define private Interval_DateTime: Interval[@T00:00:00.000, @T23:59:59.999] @@ -357,7 +357,7 @@ library IntervalTest version '1.0.0' Assert.IsNotNull(nts.name?.Name); Assert.AreEqual($"{{{SystemUri}}}Time", nts.name?.Name); - var lambda = CreateElmApi().Lambda(interval); + var lambda = ToFluentElmToolkit().Lambda(interval); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -374,7 +374,7 @@ library IntervalTest version '1.0.0' [TestMethod] public void Interval_Includes_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IntervalTest version '1.0.0' define private TestIncludesNull: Interval[1, 10] includes null @@ -395,7 +395,7 @@ library IntervalTest version '1.0.0' [TestMethod] public void Interval_Properly_Included_in_Interval_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("Interval[1, 10] properly included in Interval[null as Integer, null as Integer]"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("Interval[1, 10] properly included in Interval[null as Integer, null as Integer]"); var pii = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(pii, library); Assert.IsNull(result); @@ -404,7 +404,7 @@ public void Interval_Properly_Included_in_Interval_Null() [TestMethod] public void Interval_Null_Starts_Interval() { - var library = CreateCqlApi().MakeLibraryFromExpression("Interval[null as Integer, null as Integer] starts Interval[1, 10]"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("Interval[null as Integer, null as Integer] starts Interval[1, 10]"); var pii = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(pii, library); Assert.IsNull(result); diff --git a/Cql/CqlToElmTests/InvocationBuilderTests.cs b/Cql/CqlToElmTests/(tests)/InvocationBuilderTests.cs similarity index 97% rename from Cql/CqlToElmTests/InvocationBuilderTests.cs rename to Cql/CqlToElmTests/(tests)/InvocationBuilderTests.cs index 19e7baabe..96bf17e14 100644 --- a/Cql/CqlToElmTests/InvocationBuilderTests.cs +++ b/Cql/CqlToElmTests/(tests)/InvocationBuilderTests.cs @@ -1,6 +1,5 @@ using Hl7.Cql.CqlToElm.Builtin; using Hl7.Cql.Elm; -using CqlSdkPrototype.Cql.Internal; namespace Hl7.Cql.CqlToElm.Test { @@ -9,9 +8,16 @@ namespace Hl7.Cql.CqlToElm.Test [TestClass] public class InvocationBuilderTest : Base { - internal static InvocationBuilder InvocationBuilder => CreateCqlApi().AsInternal().Services.ServiceProvider.GetRequiredService(); - internal static ElmFactory ElmFactory => CreateCqlApi().AsInternal().Services.ServiceProvider.GetRequiredService(); - + static InvocationBuilderTest() + { + var fluentCqlToolkit = CreateFluentCqlToolkit(); + InvocationBuilder = fluentCqlToolkit.GetInvocationBuilder(); + ElmFactory = fluentCqlToolkit.GetElmFactory(); + } + + private static InvocationBuilder InvocationBuilder { get; } + private static ElmFactory ElmFactory { get; } + private static ParameterTypeSpecifier Generic(string parameterName = "T") => new ParameterTypeSpecifier { parameterName = parameterName }; private static Literal Boolean(bool value = true) => ElmFactory.Literal(value); @@ -26,6 +32,7 @@ public class InvocationBuilderTest : Base private static readonly Null Null = new Null().WithResultType(SystemTypes.AnyType); private static readonly ParameterTypeSpecifier T = new ParameterTypeSpecifier { parameterName = "T" }; + private static void AssertCompatible(FunctionDef function, Expression[] arguments, CoercionCost mostExpensive, int? totalCost = null) { var result = InvocationBuilder.MatchSignature(function, arguments); diff --git a/Cql/CqlToElmTests/IsTest.cs b/Cql/CqlToElmTests/(tests)/IsTest.cs similarity index 94% rename from Cql/CqlToElmTests/IsTest.cs rename to Cql/CqlToElmTests/(tests)/IsTest.cs index 9d479ef08..fd6960127 100644 --- a/Cql/CqlToElmTests/IsTest.cs +++ b/Cql/CqlToElmTests/(tests)/IsTest.cs @@ -11,7 +11,7 @@ public class IsTest : Base [TestMethod] public void Integer_Is_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IsTest version '1.0.0' define private Integer_Is_Decimal: 1 is System.Decimal @@ -40,7 +40,7 @@ library IsTest version '1.0.0' [TestMethod] public void True_Is_Qualified_Boolean() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IsTest version '1.0.0' define private True_Is_Qualified_Boolean: true is System.Boolean @@ -69,7 +69,7 @@ library IsTest version '1.0.0' [TestMethod] public void True_Is_Unqualified_Boolean() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IsTest version '1.0.0' define private True_Is_Unqualified_Boolean: true is Boolean @@ -98,7 +98,7 @@ library IsTest version '1.0.0' [TestMethod] public void Null_Is_Boolean() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IsTest version '1.0.0' define private Null_Is_Boolean: null is Boolean @@ -123,7 +123,7 @@ library IsTest version '1.0.0' [TestMethod] public void Null_Is_Any() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IsTest version '1.0.0' define private Null_Is_Any: null is Any @@ -147,7 +147,7 @@ library IsTest version '1.0.0' [TestMethod] public void List_Is_List_of_Qualified_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IsTest version '1.0.0' define private List_Is_List_of_Qualified_Integer: { 1,2,3 } is List @@ -174,7 +174,7 @@ library IsTest version '1.0.0' [TestMethod] public void Interval_Is_Unqualified_Integer_Interval() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IsTest version '1.0.0' define private Interval_Is_Unqualified_Integer_Interval: Interval[1, 10] is Interval @@ -200,7 +200,7 @@ library IsTest version '1.0.0' [TestMethod] public void Integer_Interval_Is_Decimal_Interval_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IsTest version '1.0.0' define private Integer_Interval_Is_Decimal_Interval_False: Interval[1, 10] is Interval @@ -226,7 +226,7 @@ library IsTest version '1.0.0' [TestMethod] public void Integer_Is_Choice() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IsTest version '1.0.0' define private Integer_Is_Choice: 1 is Choice @@ -253,7 +253,7 @@ library IsTest version '1.0.0' [TestMethod] public void String_Is_Choice_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IsTest version '1.0.0' define private String_Is_Choice_False: 'hello' is Choice @@ -281,7 +281,7 @@ library IsTest version '1.0.0' [TestMethod] public void Tuple_Is_Tuple() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IsTest version '1.0.0' define private Tuple_Is_Tuple: { x: 1, y: 2 } is Tuple { x Integer, y Integer } @@ -306,7 +306,7 @@ library IsTest version '1.0.0' [TestMethod] public void Tuple_Is_Tuple_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IsTest version '1.0.0' define private Tuple_Is_Tuple: Tuple { x: 1, y: 2 } is Tuple { x Decimal, y Integer } @@ -331,7 +331,7 @@ library IsTest version '1.0.0' private void AssertIs(Is @is, bool? expected) { - var lambda = CreateElmApi().Lambda(@is); + var lambda = ToFluentElmToolkit().Lambda(@is); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); diff --git a/Cql/CqlToElmTests/LengthTest.cs b/Cql/CqlToElmTests/(tests)/LengthTest.cs similarity index 79% rename from Cql/CqlToElmTests/LengthTest.cs rename to Cql/CqlToElmTests/(tests)/LengthTest.cs index 02349c8ea..a70e1f63c 100644 --- a/Cql/CqlToElmTests/LengthTest.cs +++ b/Cql/CqlToElmTests/(tests)/LengthTest.cs @@ -8,7 +8,7 @@ public class LengthTest : Base [TestMethod] public void LengthNullString() { - var library = CreateCqlApi().MakeLibraryFromExpression("Length(null as String)"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("Length(null as String)"); var length = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(length, library); result.Should().BeNull(); diff --git a/Cql/CqlToElmTests/LibraryTest.cs b/Cql/CqlToElmTests/(tests)/LibraryTest.cs similarity index 90% rename from Cql/CqlToElmTests/LibraryTest.cs rename to Cql/CqlToElmTests/(tests)/LibraryTest.cs index a42c6473e..e50062f01 100644 --- a/Cql/CqlToElmTests/LibraryTest.cs +++ b/Cql/CqlToElmTests/(tests)/LibraryTest.cs @@ -1,5 +1,4 @@ using Hl7.Cql.Elm; -using CqlSdkPrototype.Cql.Internal; namespace Hl7.Cql.CqlToElm.Test { @@ -9,9 +8,10 @@ public class LibraryTest : Base [TestMethod] public void Empty() { - Assert.ThrowsException(() => CreateCqlApi().MakeLibrary(string.Empty)); + var fluentCqlToolkit = CreateFluentCqlToolkit(); + Assert.ThrowsException(() => fluentCqlToolkit.MakeLibrary(string.Empty)); var ms = new MemoryStream(); - Assert.ThrowsException(() => CreateCqlApi().AsInternal().Services.CqlToElmConverter.ConvertLibrary(ms)); + Assert.ThrowsException(() => fluentCqlToolkit.GetCqlToElmConverter().ConvertLibrary(ms)); } #region Identifier @@ -19,7 +19,7 @@ public void Empty() [TestMethod] public void Identifier_AllTerms_String() { - var library = CreateCqlApi().MakeLibrary("library String version '4.0.1'"); + var library = CreateFluentCqlToolkit().MakeLibrary("library String version '4.0.1'"); Assert.IsNotNull(library); Assert.IsNotNull(library.identifier); Assert.AreEqual("String", library.identifier.id); @@ -31,7 +31,7 @@ public void Identifier_AllTerms_String() [TestMethod] public void Identifier_AllTerms_Namespace() { - var library = CreateCqlApi().MakeLibrary("library Namespace.Lib version '4.0.1'"); + var library = CreateFluentCqlToolkit().MakeLibrary("library Namespace.Lib version '4.0.1'"); Assert.IsNotNull(library); Assert.IsNotNull(library.identifier); Assert.AreEqual("Lib", library.identifier.id); @@ -43,7 +43,7 @@ public void Identifier_AllTerms_Namespace() [TestMethod] public void Identifier_Id_Only() { - var library = CreateCqlApi().MakeLibrary("library Lib"); + var library = CreateFluentCqlToolkit().MakeLibrary("library Lib"); Assert.IsNotNull(library); Assert.IsNotNull(library.identifier); Assert.AreEqual("Lib", library.identifier.id); @@ -55,7 +55,7 @@ public void Identifier_Id_Only() [TestMethod] public void Identifier_Id_Namespace() { - var library = CreateCqlApi().MakeLibrary("library Namespace.Lib"); + var library = CreateFluentCqlToolkit().MakeLibrary("library Namespace.Lib"); Assert.IsNotNull(library); Assert.IsNotNull(library.identifier); Assert.AreEqual("Lib", library.identifier.id); @@ -77,7 +77,7 @@ public void Using_AllTerms() version = "1.0.0" }; - var library = CreateCqlApi(ModelInfos: [modelInfo], Models: []) + var library = CreateFluentCqlToolkit(ModelInfos: [modelInfo], Models: []) .MakeLibrary(""" library UsingTest version '1.0.0' @@ -102,7 +102,7 @@ public void Using_AllTerms_WithNamespace() version = "1.0.0" }; - var library = CreateCqlApi(ModelInfos: [modelInfo], Models: []) + var library = CreateFluentCqlToolkit(ModelInfos: [modelInfo], Models: []) .MakeLibrary(""" library UsingTest version '1.0.0' @@ -126,7 +126,7 @@ public void Using_NoVersion_LocalIdentifier() version = "1.0.0" }; - var library = CreateCqlApi(ModelInfos: [modelInfo], Models: []) + var library = CreateFluentCqlToolkit(ModelInfos: [modelInfo], Models: []) .MakeLibrary(""" library UsingTest version '1.0.0' @@ -150,7 +150,7 @@ public void Using_Version_NoIdentifier() version = "1.0.0" }; - var library = CreateCqlApi(ModelInfos: [modelInfo], Models: []) + var library = CreateFluentCqlToolkit(ModelInfos: [modelInfo], Models: []) .MakeLibrary(""" library UsingTest version '1.0.0' @@ -174,7 +174,7 @@ public void Using_NoVersion_NoIdentifier() version = "1.0.0" }; - var library = CreateCqlApi(ModelInfos: [modelInfo], Models: []) + var library = CreateFluentCqlToolkit(ModelInfos: [modelInfo], Models: []) .MakeLibrary(""" library UsingTest version '1.0.0' @@ -198,7 +198,7 @@ public void Using_Duplicate_System_NoLocalAlias() version = "1.0.0" }; - var library = CreateCqlApi(ModelInfos: [modelInfo], Models: []) + var library = CreateFluentCqlToolkit(ModelInfos: [modelInfo], Models: []) .MakeLibrary(""" library UsingTest version '1.0.0' @@ -219,7 +219,7 @@ library UsingTest version '1.0.0' [TestMethod] public void Include_AllTerms() { - var library = CreateCqlApi() + var library = CreateFluentCqlToolkit() .MakeLibrary(""" library IncludeTest version '1.0.0' @@ -236,7 +236,7 @@ include MyLibrary version '1.0.0' called Derp [TestMethod] public void Include_AllTerms_WithNamespace() { - var library = CreateCqlApi() + var library = CreateFluentCqlToolkit() .MakeLibrary(""" library IncludeTest version '1.0.0' @@ -253,7 +253,7 @@ include Namespace.MyLibrary version '1.0.0' called Derp [TestMethod] public void Include_NoVersion_LocalIdentifier() { - var library = CreateCqlApi() + var library = CreateFluentCqlToolkit() .MakeLibrary(""" library IncludeTest version '1.0.0' @@ -270,7 +270,7 @@ include Namespace.MyLibrary called Derp [TestMethod] public void Include_Version_NoIdentifier() { - var library = CreateCqlApi() + var library = CreateFluentCqlToolkit() .MakeLibrary(""" library IncludeTest version '1.0.0' @@ -292,7 +292,7 @@ include Namespace.MyLibrary version '1.0.0' [TestMethod] public void Include_NoVersion_NoIdentifier() { - var library = CreateCqlApi() + var library = CreateFluentCqlToolkit() .MakeLibrary(""" library IncludeTest version '1.0.0' @@ -318,7 +318,7 @@ include Namespace.MyLibrary [TestMethod] public void CodeSystem_AllTerms() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' private codesystem Name: 'id' version 'version string' @@ -334,7 +334,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void CodeSystem_Without_Access_Modifier() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' codesystem Name: 'id' version 'version string' @@ -350,7 +350,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void CodeSystem_Without_Version() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' private codesystem Name: 'id' @@ -366,7 +366,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void CodeSystem_Minimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' codesystem Name: 'id' @@ -382,7 +382,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void CodeSystems_Two() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' private codesystem Name: 'id' version 'version string' @@ -409,7 +409,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void ValueSet_AllTerms_OneCodeSystems() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' private valueset Name: 'id' version 'version string' codesystems { lib.cs1 } @@ -429,7 +429,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void ValueSet_AllTerms_EvenCodeSystems() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' private valueset Name: 'id' version 'version string' codesystems { lib.cs1, cs2 } @@ -452,7 +452,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void ValueSet_AllTerms_OddCodeSystems() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' private valueset Name: 'id' version 'version string' codesystems { lib.cs1, cs2, lib2.cs3 } @@ -476,7 +476,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void ValueSet_Without_Access_Modifier() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' valueset Name: 'id' version 'version string' @@ -492,7 +492,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void ValueSet_Without_Version() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' private valueset Name: 'id' @@ -508,7 +508,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void ValueSet_Minimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' valueset Name: 'id' @@ -524,7 +524,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void ValueSets_Two() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' private valueset Name: 'id' version 'version string' @@ -547,7 +547,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void ValueSet_CodeSystems_NoVersion() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' valueset Name: 'id' codesystems { lib.cs1, cs2, lib2.cs3 } @@ -575,7 +575,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void Code_WithoutDisplay() { - var library = CreateCqlApi() + var library = CreateFluentCqlToolkit() .MakeLibrary(""" library IncludeTest version '1.0.0' @@ -594,7 +594,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void Code_AccessModifier_WithoutDisplay() { - var library = CreateCqlApi() + var library = CreateFluentCqlToolkit() .MakeLibrary(""" library IncludeTest version '1.0.0' @@ -614,7 +614,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void Code_WithDisplay() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' code Name: 'id' from lib.cs1 display 'Code display text' @@ -633,7 +633,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void Code_AllTerms() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' private code Name: 'id' from lib.cs1 display 'Code display text' @@ -656,7 +656,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void Concept_AllTerms() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' private concept Name: { lib.code1, code2, lib2.code3 } display 'My concept' @@ -682,7 +682,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void Concept_NoDisplay() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' concept Name: { lib.code1 } @@ -702,7 +702,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void Concept_Build() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' codesystem "SystemA": 'http://hl7.org' @@ -712,7 +712,7 @@ library IncludeTest version '1.0.0' private concept Name: { "code1", "code2", "code3" } display 'My concept' """); - _ = CreateElmApi().ProcessLibrary(library); + _ = ToFluentElmToolkit().ProcessLibrary(library); } #endregion @@ -722,7 +722,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void Paramter_AllTerms() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' private parameter Name System.String default 'default value' @@ -738,7 +738,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void Parameter_AllTermsWithCast() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' private parameter Name System.Decimal default 1 @@ -753,7 +753,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void Parameter_Default() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' private parameter Name default 'default value' @@ -767,7 +767,7 @@ library IncludeTest version '1.0.0' [TestMethod] public void Parameter_Type() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' private parameter Name System.String @@ -781,7 +781,7 @@ private parameter Name System.String [TestMethod] public void Parameter_None() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IncludeTest version '1.0.0' private parameter Name diff --git a/Cql/CqlToElmTests/ListTest.cs b/Cql/CqlToElmTests/(tests)/ListTest.cs similarity index 92% rename from Cql/CqlToElmTests/ListTest.cs rename to Cql/CqlToElmTests/(tests)/ListTest.cs index ff4f955f4..dcf02a563 100644 --- a/Cql/CqlToElmTests/ListTest.cs +++ b/Cql/CqlToElmTests/(tests)/ListTest.cs @@ -10,7 +10,7 @@ public class ListTest : Base [TestMethod] public void Empty_List() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ListTest version '1.0.0' define private Empty_List: { } @@ -30,7 +30,7 @@ library ListTest version '1.0.0' [TestMethod] public void List_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ListTest version '1.0.0' define private List_Integer: { 1, 2, 3 } @@ -50,7 +50,7 @@ library ListTest version '1.0.0' [TestMethod] public void List_Mixed_ToQuantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ListTest version '1.0.0' define private List_Mixed_ToQuantity: { 1, 2L, 3.0, 4.0 '1' } @@ -75,7 +75,7 @@ library ListTest version '1.0.0' [TestMethod] public void List_Mixed_ToDecimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ListTest version '1.0.0' define private List_Mixed_ToDecimal: { 1, 2L, 3.0 } @@ -95,7 +95,7 @@ library ListTest version '1.0.0' [TestMethod] public void List_Mixed_ToLong() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ListTest version '1.0.0' define private List_Mixed_ToLong: { 1, 2L } @@ -115,7 +115,7 @@ library ListTest version '1.0.0' [TestMethod] public void List_Mixed_Any() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ListTest version '1.0.0' define private List_Mixed_Any: { 1, 'string' } @@ -136,7 +136,7 @@ library ListTest version '1.0.0' [TestMethod] public void List_Nulls() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library ListTest version '1.0.0' define private List_Nulls: { null, null } @@ -156,7 +156,7 @@ library ListTest version '1.0.0' [TestMethod] public void Take_Null_Integer() { - var library = CreateCqlApi().MakeLibraryFromExpression("Take(null, 3)"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("Take(null, 3)"); var slice = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var @as = slice.source.Should().BeOfType().Subject; @as.Should().HaveType(SystemTypes.AnyType.ToListType()); @@ -174,7 +174,7 @@ public void Take_Null_Integer() public void List_Tuple_Different_Orders() { // we order tuple types & their elements alphabetically even when not ordered that way in the CQL - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library ListTest version '1.0.0' define private l: { Tuple { b: 2, a: 1 }, Tuple { a: 1, b: 2 } } diff --git a/Cql/CqlToElmTests/LiteralTest.cs b/Cql/CqlToElmTests/(tests)/LiteralTest.cs similarity index 96% rename from Cql/CqlToElmTests/LiteralTest.cs rename to Cql/CqlToElmTests/(tests)/LiteralTest.cs index e13736ddb..c6e0736ea 100644 --- a/Cql/CqlToElmTests/LiteralTest.cs +++ b/Cql/CqlToElmTests/(tests)/LiteralTest.cs @@ -1,4 +1,3 @@ -using CqlSdkPrototype.Cql.Internal; using Hl7.Cql.CqlToElm.Builtin; using Hl7.Cql.Elm; @@ -10,12 +9,12 @@ namespace Hl7.Cql.CqlToElm.Test public class LiteralTest : Base { - private static InvocationBuilder InvocationBuilder => CreateCqlApi().AsInternal().Services.ServiceProvider.GetRequiredService(); + private static InvocationBuilder InvocationBuilder => CreateFluentCqlToolkit().GetInvocationBuilder(); [TestMethod] public void String_Literal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DecimalTest version '1.0.0' define private String_Literal: 'test' @@ -44,7 +43,7 @@ library DecimalTest version '1.0.0' [TestMethod] public void Decimal_Literal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DecimalTest version '1.0.0' define private Decimal_Literal: 1.0 @@ -71,7 +70,7 @@ library DecimalTest version '1.0.0' [TestMethod] public void Decimal_Negative_Literal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DecimalTest version '1.0.0' define private Decimal_Literal: -123.567 @@ -98,21 +97,21 @@ library DecimalTest version '1.0.0' [TestMethod] public void Decimal_Errors() { - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library Decimal_Errors_1 version '1.0.0' define private Decimal_Literal: 0.123456789 """, "Decimal literals cannot have a mantissa longer than 8 digits."); // exactly 28 digits - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library Decimal_Errors_2 version '1.0.0' define private Decimal_Literal: -12345678901234567890.12345678 """).ShouldSucceed(); // 29 digits - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library Decimal_Errors_3 version '1.0.0' define private Decimal_Literal: -123456789012345678901.12345678 @@ -127,7 +126,7 @@ library Decimal_Errors_3 version '1.0.0' [TestMethod] public void Integer_Literal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IntegerTest version '1.0.0' define private Integer_Literal: 1 @@ -154,7 +153,7 @@ library IntegerTest version '1.0.0' [TestMethod] public void Integer_Negative() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IntegerTest version '1.0.0' define private Integer_Literal: -123456789 @@ -182,13 +181,13 @@ library IntegerTest version '1.0.0' public void Integer_Overflows() { // minimum long is -9,223,372,036,854,775,808 - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library Decimal_Errors_1 version '1.0.0' define private Overflow_Literal: -9223372036854775809 """, "Unparseable numeric literal*."); - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library Decimal_Errors_1 version '1.0.0' define private Overflow_Literal: 9223372036854775808 @@ -204,7 +203,7 @@ public void Long_Literal() { // max value of an int is 2,147,483,647 // this will be parsed as a long - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library LongTest version '1.0.0' define private Long_Literal: 2147483648L @@ -231,7 +230,7 @@ public void Long_Negative() { // max value of an int is 2,147,483,647 // this will be parsed as a long - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library LongTest version '1.0.0' define private Long_Literal: -2147483649L @@ -258,7 +257,7 @@ library LongTest version '1.0.0' public void Long_MinValue() { - var lib = CreateCqlApi().MakeLibraryFromExpression("-9223372036854775808L"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("-9223372036854775808L"); var literal = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(false); literal.Should().HaveType(SystemTypes.LongType); } @@ -270,7 +269,7 @@ public void Long_MinValue() [TestMethod] public void Boolean_Literal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TrueTest version '1.0.0' define private True_Literal: true @@ -293,7 +292,7 @@ library TrueTest version '1.0.0' Assert.AreEqual("true", literal.value); } - library = CreateCqlApi().MakeLibrary(""" + library = CreateFluentCqlToolkit().MakeLibrary(""" library FalseTest version '1.0.0' define private False_Literal: false @@ -321,7 +320,7 @@ library FalseTest version '1.0.0' [TestMethod] public void Null_Literal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library NullTest version '1.0.0' define private Null_Test: null @@ -349,7 +348,7 @@ library NullTest version '1.0.0' [TestMethod] public void Date_Literal_Day_Precision() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DateTest version '1.0.0' define private Date_Literal: @2023-01-02 @@ -417,7 +416,7 @@ library DateTest version '1.0.0' [TestMethod] public void Date_Literal_Month_Precision() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DateTest version '1.0.0' define private Date_Literal: @2023-01 @@ -472,7 +471,7 @@ library DateTest version '1.0.0' [TestMethod] public void Date_Literal_Year_Precision() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DateTest version '1.0.0' define private Date_Literal: @2023 @@ -519,7 +518,7 @@ library DateTest version '1.0.0' [TestMethod] public void DateTime_Literal_Millisecond_Precision() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DateTest version '1.0.0' define private Date_Literal: @2023-01-02T01:23:45.678+01:30 @@ -652,7 +651,7 @@ library DateTest version '1.0.0' [TestMethod] public void DateTime_Literal_Second_Precision() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DateTest version '1.0.0' define private Date_Literal: @2023-01-02T01:23:45+01:30 @@ -773,7 +772,7 @@ library DateTest version '1.0.0' [TestMethod] public void DateTime_Literal_Minute_Precision() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DateTest version '1.0.0' define private Date_Literal: @2023-01-02T01:23+01:30 @@ -882,7 +881,7 @@ library DateTest version '1.0.0' [TestMethod] public void DateTime_Literal_Hour_Precision() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DateTest version '1.0.0' define private Date_Literal: @2023-01-02T01+01:30 @@ -979,7 +978,7 @@ library DateTest version '1.0.0' [TestMethod] public void DateTime_Literal_Hour_Precision_NoOffset() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DateTest version '1.0.0' define private Date_Literal: @2023-01-02T01 @@ -1064,7 +1063,7 @@ library DateTest version '1.0.0' [TestMethod] public void DateTime_Literal_T() { - var lib = CreateCqlApi().MakeLibraryFromExpression("@2016T"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("@2016T"); var dt = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var yearLiteral = dt.year.Should().BeOfType().Subject; yearLiteral.value.Should().Be("2016"); @@ -1074,7 +1073,7 @@ public void DateTime_Literal_T() [TestMethod] public void Time_Literal_Millisecond_Precision() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TimeTest version '1.0.0' define private Time_Literal: @T01:23:45.678 @@ -1156,7 +1155,7 @@ library TimeTest version '1.0.0' [TestMethod] public void Time_Literal_Second_Precision() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TimeTest version '1.0.0' define private Time_Literal: @T01:23:45 @@ -1222,7 +1221,7 @@ library TimeTest version '1.0.0' [TestMethod] public void Time_Literal_Minute_Precision() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TimeTest version '1.0.0' define private Time_Literal: @T01:23 @@ -1276,7 +1275,7 @@ library TimeTest version '1.0.0' [TestMethod] public void Time_Literal_Hour_Precision() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TimeTest version '1.0.0' define private Time_Literal: @T01 @@ -1322,7 +1321,7 @@ library TimeTest version '1.0.0' [TestMethod] public void Quantity_Literal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library QuantityTest version '1.0.0' define private Quantity_Literal: 6.2 'gm/cm3' @@ -1344,7 +1343,7 @@ library QuantityTest version '1.0.0' [TestMethod] public void Quantity_Year() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library QuantityTest version '1.0.0' define private Quantity_Literal: 6 year @@ -1366,7 +1365,7 @@ library QuantityTest version '1.0.0' [TestMethod] public void Quantity_Years() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library QuantityTest version '1.0.0' define private Quantity_Literal: 6 years @@ -1388,7 +1387,7 @@ library QuantityTest version '1.0.0' [TestMethod] public void Quantity_Month() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library QuantityTest version '1.0.0' define private Quantity_Literal: 1.245671213 month @@ -1410,7 +1409,7 @@ library QuantityTest version '1.0.0' [TestMethod] public void Quantity_Months() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library QuantityTest version '1.0.0' define private Quantity_Literal: 1.245671213 months @@ -1432,7 +1431,7 @@ library QuantityTest version '1.0.0' [TestMethod] public void Quantity_Day() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library QuantityTest version '1.0.0' define private Quantity_Literal: 0 day @@ -1454,7 +1453,7 @@ library QuantityTest version '1.0.0' [TestMethod] public void Quantity_Days() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library QuantityTest version '1.0.0' define private Quantity_Literal: 0 days @@ -1476,7 +1475,7 @@ library QuantityTest version '1.0.0' [TestMethod] public void Quantity_Hour() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library QuantityTest version '1.0.0' define private Quantity_Literal: 0.0 hour @@ -1498,7 +1497,7 @@ library QuantityTest version '1.0.0' [TestMethod] public void Quantity_Hours() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library QuantityTest version '1.0.0' define private Quantity_Literal: 0.0 hours @@ -1520,7 +1519,7 @@ library QuantityTest version '1.0.0' [TestMethod] public void Quantity_Minute() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library QuantityTest version '1.0.0' define private Quantity_Literal: 0.25 minute @@ -1542,7 +1541,7 @@ library QuantityTest version '1.0.0' [TestMethod] public void Quantity_Minutes() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library QuantityTest version '1.0.0' define private Quantity_Literal: 0.25 minutes @@ -1564,7 +1563,7 @@ library QuantityTest version '1.0.0' [TestMethod] public void Quantity_Second() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library QuantityTest version '1.0.0' define private Quantity_Literal: 1 second @@ -1587,7 +1586,7 @@ library QuantityTest version '1.0.0' [TestMethod] public void Quantity_Seconds() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library QuantityTest version '1.0.0' define private Quantity_Literal: 1 seconds @@ -1609,7 +1608,7 @@ library QuantityTest version '1.0.0' [TestMethod] public void Quantity_Millisecond() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library QuantityTest version '1.0.0' define private Quantity_Literal: 2000000 millisecond @@ -1631,7 +1630,7 @@ library QuantityTest version '1.0.0' [TestMethod] public void Quantity_Milliseconds() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library QuantityTest version '1.0.0' define private Quantity_Literal: 2000000 milliseconds @@ -1655,7 +1654,7 @@ library QuantityTest version '1.0.0' [TestMethod] public void Ratio_Literal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library RatioTest version '1.0.0' define private Ratio_Literal: 6 'gm' : 10 'cm3' @@ -1681,9 +1680,9 @@ library RatioTest version '1.0.0' [TestMethod] public void Ceiling_1D() { - var input = CreateCqlApi().MakeLibraryFromExpression("Ceiling(1.0)"); + var input = CreateFluentCqlToolkit().MakeLibraryFromExpression("Ceiling(1.0)"); var ceiling = input.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); - var output = CreateCqlApi().MakeLibraryFromExpression("1"); + var output = CreateFluentCqlToolkit().MakeLibraryFromExpression("1"); var literal = output.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); // var context = FhirCqlContext.ForBundle(); var equalsOverload = InvocationBuilder.MatchSignature(SystemLibrary.Equal, ceiling, literal); diff --git a/Cql/CqlToElmTests/MeetsTest.cs b/Cql/CqlToElmTests/(tests)/MeetsTest.cs similarity index 94% rename from Cql/CqlToElmTests/MeetsTest.cs rename to Cql/CqlToElmTests/(tests)/MeetsTest.cs index 80c0a7d00..cd268528c 100644 --- a/Cql/CqlToElmTests/MeetsTest.cs +++ b/Cql/CqlToElmTests/(tests)/MeetsTest.cs @@ -8,7 +8,7 @@ public class MeetsTest : Base [TestMethod] public void Meets() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library MeetsTest version '1.0.0' define private Meets: Interval[6, 10] meets Interval[0, 5] @@ -37,7 +37,7 @@ library MeetsTest version '1.0.0' [TestMethod] public void Meets_Before() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library MeetsTest version '1.0.0' define private Meets_Before: Interval[-5, -1] meets before Interval[0, 5] @@ -66,7 +66,7 @@ library MeetsTest version '1.0.0' [TestMethod] public void Meets_After() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library MeetsTest version '1.0.0' define private Meets_After: Interval[6, 10] meets after Interval[0, 7] @@ -95,7 +95,7 @@ library MeetsTest version '1.0.0' [TestMethod] public void Meets_Is_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library MeetsTest version '1.0.0' define private Meets_Is_Null: Interval[6, 10] meets (null as Interval) @@ -123,7 +123,7 @@ library MeetsTest version '1.0.0' [TestMethod] public void Meets_After_Day() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library MeetsTest version '1.0.0' define private Meets_After_Day: Interval[@2023-03-01, @2023-06-01] meets after month of Interval[@2023-01-01, @2023-03-01] @@ -152,7 +152,7 @@ library MeetsTest version '1.0.0' [TestMethod] public void Meets_Day() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library MeetsTest version '1.0.0' define private Meets_Day: Interval[@2023-01-01, @2023-06-01] meets month of Interval[@2023-07-01, @2023-10-01] @@ -181,7 +181,7 @@ library MeetsTest version '1.0.0' [TestMethod] public void Meets_After_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("Interval(null, 5] meets after Interval[11, null)"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("Interval(null, 5] meets after Interval[11, null)"); var meetsAfter = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(meetsAfter, library); result.Should().BeFalse(); diff --git a/Cql/CqlToElmTests/ModelProviderTest.cs b/Cql/CqlToElmTests/(tests)/ModelProviderTest.cs similarity index 100% rename from Cql/CqlToElmTests/ModelProviderTest.cs rename to Cql/CqlToElmTests/(tests)/ModelProviderTest.cs diff --git a/Cql/CqlToElmTests/ModelTest.cs b/Cql/CqlToElmTests/(tests)/ModelTest.cs similarity index 74% rename from Cql/CqlToElmTests/ModelTest.cs rename to Cql/CqlToElmTests/(tests)/ModelTest.cs index 674f4dd69..1fcea6e89 100644 --- a/Cql/CqlToElmTests/ModelTest.cs +++ b/Cql/CqlToElmTests/(tests)/ModelTest.cs @@ -8,8 +8,8 @@ public class ModelTest : Base [TestMethod] public void Quantity_Is_Ambiguous() { - var cqlApi = CreateCqlApi(AmbiguousTypeBehavior: AmbiguousTypeBehavior.Error); - var lib = cqlApi.MakeLibrary(""" + var cqlToolkit = CreateFluentCqlToolkit(AmbiguousTypeBehavior: AmbiguousTypeBehavior.Error); + var lib = cqlToolkit.MakeLibrary(""" library Test version '1.0.0' using FHIR version '4.0.1' @@ -23,8 +23,8 @@ define function f(q Quantity): q [TestMethod] public void Quantity_Prefer_System() { - var cqlApi = CreateCqlApi(AmbiguousTypeBehavior: AmbiguousTypeBehavior.PreferSystem); - var lib = cqlApi.MakeLibrary(""" + var cqlToolkit = CreateFluentCqlToolkit(AmbiguousTypeBehavior: AmbiguousTypeBehavior.PreferSystem); + var lib = cqlToolkit.MakeLibrary(""" library Test version '1.0.0' using FHIR version '4.0.1' @@ -38,8 +38,8 @@ define function f(q Quantity): q [TestMethod] public void Quantity_Prefer_Model() { - var cqlApi = CreateCqlApi(AmbiguousTypeBehavior: AmbiguousTypeBehavior.PreferModel); - var lib = cqlApi.MakeLibrary(""" + var cqlToolkit = CreateFluentCqlToolkit(AmbiguousTypeBehavior: AmbiguousTypeBehavior.PreferModel); + var lib = cqlToolkit.MakeLibrary(""" library Test version '1.0.0' using FHIR version '4.0.1' diff --git a/Cql/CqlToElmTests/ModuloTest.cs b/Cql/CqlToElmTests/(tests)/ModuloTest.cs similarity index 95% rename from Cql/CqlToElmTests/ModuloTest.cs rename to Cql/CqlToElmTests/(tests)/ModuloTest.cs index a7841d051..47a9f9288 100644 --- a/Cql/CqlToElmTests/ModuloTest.cs +++ b/Cql/CqlToElmTests/(tests)/ModuloTest.cs @@ -13,7 +13,7 @@ public class ModuloTest : Base [TestMethod] public void Modulo_Integer_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Integer_by_Integer version '1.0.0' define private Modulo_Integer_by_Integer: 4 mod 2 @@ -58,7 +58,7 @@ library Modulo_Integer_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(int?)); @@ -69,7 +69,7 @@ library Modulo_Integer_by_Integer version '1.0.0' [TestMethod] public void Modulo_Integer_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Integer_by_Long version '1.0.0' define private Modulo_Integer_by_Long: 3 mod 2L @@ -114,7 +114,7 @@ library Modulo_Integer_by_Long version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -125,7 +125,7 @@ library Modulo_Integer_by_Long version '1.0.0' [TestMethod] public void Modulo_Integer_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Integer_by_Decimal version '1.0.0' define private Modulo_Integer_by_Decimal: 3 mod 2.0 @@ -170,7 +170,7 @@ library Modulo_Integer_by_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -181,7 +181,7 @@ library Modulo_Integer_by_Decimal version '1.0.0' [TestMethod] public void Modulo_Integer_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Integer_by_Quantity version '1.0.0' define private Modulo_Integer_by_Quantity: 10 mod 6.0 '1' @@ -226,7 +226,7 @@ library Modulo_Integer_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -241,7 +241,7 @@ library Modulo_Integer_by_Quantity version '1.0.0' [TestMethod] public void Modulo_Integer_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Integer_by_Null version '1.0.0' define private Modulo_Integer_by_Null: 1 mod null @@ -285,7 +285,7 @@ library Modulo_Integer_by_Null version '1.0.0' Assert.IsNotNull(lhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Integer", lhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -295,7 +295,7 @@ library Modulo_Integer_by_Null version '1.0.0' [TestMethod] public void Modulo_Null_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Null_by_Integer version '1.0.0' define private Modulo_Null_by_Integer: null mod 1 @@ -339,7 +339,7 @@ library Modulo_Null_by_Integer version '1.0.0' Assert.IsNotNull(rhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -353,7 +353,7 @@ library Modulo_Null_by_Integer version '1.0.0' [TestMethod] public void Modulo_Long_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Long_by_Integer version '1.0.0' define private Modulo_Long_by_Integer: 10L mod 2 @@ -398,7 +398,7 @@ library Modulo_Long_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -409,7 +409,7 @@ library Modulo_Long_by_Integer version '1.0.0' [TestMethod] public void Modulo_Long_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Long_by_Long version '1.0.0' define private Modulo_Long_by_Long: 100L mod 9L @@ -454,7 +454,7 @@ library Modulo_Long_by_Long version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -465,7 +465,7 @@ library Modulo_Long_by_Long version '1.0.0' [TestMethod] public void Modulo_Long_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Long_by_Decimal version '1.0.0' define private Modulo_Long_by_Decimal: -3L mod 2.0 @@ -510,7 +510,7 @@ library Modulo_Long_by_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -521,7 +521,7 @@ library Modulo_Long_by_Decimal version '1.0.0' [TestMethod] public void Modulo_Long_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Long_by_Quantity version '1.0.0' define private Modulo_Long_by_Quantity: 20L mod 3.0 '1' @@ -566,7 +566,7 @@ library Modulo_Long_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -580,7 +580,7 @@ library Modulo_Long_by_Quantity version '1.0.0' [TestMethod] public void Modulo_Long_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Long_by_Null version '1.0.0' define private Modulo_Long_by_Null: 1L mod null @@ -624,7 +624,7 @@ library Modulo_Long_by_Null version '1.0.0' Assert.IsNotNull(lhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Long", lhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -634,7 +634,7 @@ library Modulo_Long_by_Null version '1.0.0' [TestMethod] public void Modulo_Null_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Null_by_Long version '1.0.0' define private Modulo_Null_by_Long: null mod 1L @@ -678,7 +678,7 @@ library Modulo_Null_by_Long version '1.0.0' Assert.IsNotNull(rhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -692,7 +692,7 @@ library Modulo_Null_by_Long version '1.0.0' [TestMethod] public void Modulo_Decimal_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Decimal_by_Integer version '1.0.0' define private Modulo_Decimal_by_Integer: 0.0 mod 3 @@ -737,7 +737,7 @@ library Modulo_Decimal_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -748,7 +748,7 @@ library Modulo_Decimal_by_Integer version '1.0.0' [TestMethod] public void Modulo_Decimal_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DefaultConverter version '1.0.0' define private DefaultConverter: 5.0 mod 2L @@ -793,7 +793,7 @@ library DefaultConverter version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -804,7 +804,7 @@ library DefaultConverter version '1.0.0' [TestMethod] public void Modulo_Decimal_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Decimal_by_Decimal version '1.0.0' define private Modulo_Decimal_by_Decimal: 10.0 mod 3.0 @@ -849,7 +849,7 @@ library Modulo_Decimal_by_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -860,7 +860,7 @@ library Modulo_Decimal_by_Decimal version '1.0.0' [TestMethod] public void Modulo_Decimal_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Decimal_by_Quantity version '1.0.0' define private Modulo_Decimal_by_Quantity: 3.0 mod 2.0 '1' @@ -905,7 +905,7 @@ library Modulo_Decimal_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -919,7 +919,7 @@ library Modulo_Decimal_by_Quantity version '1.0.0' [TestMethod] public void Modulo_Decimal_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Decimal_by_Null version '1.0.0' define private Modulo_Decimal_by_Null: 1.0 mod null @@ -963,7 +963,7 @@ library Modulo_Decimal_by_Null version '1.0.0' Assert.IsNotNull(lhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", lhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -973,7 +973,7 @@ library Modulo_Decimal_by_Null version '1.0.0' [TestMethod] public void Modulo_Null_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Null_by_Decimal version '1.0.0' define private Modulo_Null_by_Decimal: null mod 1.0 @@ -1017,7 +1017,7 @@ library Modulo_Null_by_Decimal version '1.0.0' Assert.IsNotNull(rhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -1031,7 +1031,7 @@ library Modulo_Null_by_Decimal version '1.0.0' [TestMethod] public void Modulo_Quantity_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Quantity_by_Quantity version '1.0.0' define private Modulo_Quantity_by_Quantity: 3.0 '1' mod 2.0 '1' @@ -1076,7 +1076,7 @@ library Modulo_Quantity_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -1090,7 +1090,7 @@ library Modulo_Quantity_by_Quantity version '1.0.0' [TestMethod] public void Modulo_Quantity_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Quantity_by_Null version '1.0.0' define private Modulo_Quantity_by_Null: 3.0 '1' mod null @@ -1135,7 +1135,7 @@ library Modulo_Quantity_by_Null version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -1145,7 +1145,7 @@ library Modulo_Quantity_by_Null version '1.0.0' [TestMethod] public void Modulo_Null_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Modulo_Null_by_Quantity version '1.0.0' define private Modulo_Null_by_Quantity: null mod 3.0 '1' @@ -1190,7 +1190,7 @@ library Modulo_Null_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(modulo); + var lambda = ToFluentElmToolkit().Lambda(modulo); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); diff --git a/Cql/CqlToElmTests/MultiplicationTest.cs b/Cql/CqlToElmTests/(tests)/MultiplicationTest.cs similarity index 95% rename from Cql/CqlToElmTests/MultiplicationTest.cs rename to Cql/CqlToElmTests/(tests)/MultiplicationTest.cs index 513d30f33..e3ec9dd12 100644 --- a/Cql/CqlToElmTests/MultiplicationTest.cs +++ b/Cql/CqlToElmTests/(tests)/MultiplicationTest.cs @@ -13,7 +13,7 @@ public class MultiplicationTest : Base [TestMethod] public void Multiply_Integer_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Integer_to_Integer version '1.0.0' define private Multiply_Integer_to_Integer: 2 * 3 @@ -58,7 +58,7 @@ library Multiply_Integer_to_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(int?)); @@ -69,7 +69,7 @@ library Multiply_Integer_to_Integer version '1.0.0' [TestMethod] public void Multiply_Integer_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Integer_to_Integer version '1.0.0' define private Multiply_Integer_to_Integer: 2 * 3L @@ -114,7 +114,7 @@ library Multiply_Integer_to_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -125,7 +125,7 @@ library Multiply_Integer_to_Integer version '1.0.0' [TestMethod] public void Multiply_Integer_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Integer_to_Integer version '1.0.0' define private Multiply_Integer_to_Integer: 2 * 3.0 @@ -170,7 +170,7 @@ library Multiply_Integer_to_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -181,7 +181,7 @@ library Multiply_Integer_to_Integer version '1.0.0' [TestMethod] public void Multiply_Integer_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Integer_by_Quantity version '1.0.0' define private Multiply_Integer_by_Quantity: 2 * 3.0 '1' @@ -226,7 +226,7 @@ library Multiply_Integer_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -241,7 +241,7 @@ library Multiply_Integer_by_Quantity version '1.0.0' [TestMethod] public void Multiply_Integer_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Integer_by_Null version '1.0.0' define private Product: 1 * null @@ -285,7 +285,7 @@ library Multiply_Integer_by_Null version '1.0.0' Assert.IsNotNull(lhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Integer", lhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -295,7 +295,7 @@ library Multiply_Integer_by_Null version '1.0.0' [TestMethod] public void Multiply_Null_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Integer_by_Null version '1.0.0' define private Product: null * 1 @@ -339,7 +339,7 @@ library Multiply_Integer_by_Null version '1.0.0' Assert.IsNotNull(rhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -353,7 +353,7 @@ library Multiply_Integer_by_Null version '1.0.0' [TestMethod] public void Multiply_Long_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Long_by_Integer version '1.0.0' define private Multiply_Integer_to_Integer: -2L * 3 @@ -398,7 +398,7 @@ library Multiply_Long_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -409,7 +409,7 @@ library Multiply_Long_by_Integer version '1.0.0' [TestMethod] public void Multiply_Long_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Long_by_Integer version '1.0.0' define private Multiply_Integer_to_Integer: -2L * 3L @@ -454,7 +454,7 @@ library Multiply_Long_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -465,7 +465,7 @@ library Multiply_Long_by_Integer version '1.0.0' [TestMethod] public void Multiply_Long_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Long_by_Integer version '1.0.0' define private Multiply_Integer_to_Integer: -2L * 3.0 @@ -510,7 +510,7 @@ library Multiply_Long_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -521,7 +521,7 @@ library Multiply_Long_by_Integer version '1.0.0' [TestMethod] public void Multiply_Long_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Integer_by_Quantity version '1.0.0' define private Multiply_Integer_by_Quantity: 2L * 3.0 '1' @@ -566,7 +566,7 @@ library Multiply_Integer_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -580,7 +580,7 @@ library Multiply_Integer_by_Quantity version '1.0.0' [TestMethod] public void Multiply_Long_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Long_by_Null version '1.0.0' define private Product: 1L * null @@ -624,7 +624,7 @@ library Multiply_Long_by_Null version '1.0.0' Assert.IsNotNull(lhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Long", lhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -634,7 +634,7 @@ library Multiply_Long_by_Null version '1.0.0' [TestMethod] public void Multiply_Null_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Integer_by_Null version '1.0.0' define private Product: null * 1L @@ -678,7 +678,7 @@ library Multiply_Integer_by_Null version '1.0.0' Assert.IsNotNull(rhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -692,7 +692,7 @@ library Multiply_Integer_by_Null version '1.0.0' [TestMethod] public void Multiply_Decimal_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Decimal_by_Integer version '1.0.0' define private Multiply_Integer_to_Integer: 0.0 * 3 @@ -737,7 +737,7 @@ library Multiply_Decimal_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -748,7 +748,7 @@ library Multiply_Decimal_by_Integer version '1.0.0' [TestMethod] public void Multiply_Decimal_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Decimal_by_Integer version '1.0.0' define private Multiply_Integer_to_Integer: 5.0 * 5L @@ -793,7 +793,7 @@ library Multiply_Decimal_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -804,7 +804,7 @@ library Multiply_Decimal_by_Integer version '1.0.0' [TestMethod] public void Multiply_Decimal_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Decimal_by_Integer version '1.0.0' define private Multiply_Integer_to_Integer: -10.0 * 10.0 @@ -849,7 +849,7 @@ library Multiply_Decimal_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -860,7 +860,7 @@ library Multiply_Decimal_by_Integer version '1.0.0' [TestMethod] public void Multiply_Decimal_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Integer_by_Quantity version '1.0.0' define private Multiply_Integer_by_Quantity: 2.0 * 3.0 '1' @@ -905,7 +905,7 @@ library Multiply_Integer_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -919,7 +919,7 @@ library Multiply_Integer_by_Quantity version '1.0.0' [TestMethod] public void Multiply_Decimal_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Decimal_by_Null version '1.0.0' define private Product: 1.0 * null @@ -963,7 +963,7 @@ library Multiply_Decimal_by_Null version '1.0.0' Assert.IsNotNull(lhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", lhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -973,7 +973,7 @@ library Multiply_Decimal_by_Null version '1.0.0' [TestMethod] public void Multiply_Null_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Integer_by_Null version '1.0.0' define private Product: null * 1.0 @@ -1017,7 +1017,7 @@ library Multiply_Integer_by_Null version '1.0.0' Assert.IsNotNull(rhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -1031,7 +1031,7 @@ library Multiply_Integer_by_Null version '1.0.0' [TestMethod] public void Multiply_Quantity_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Quantity_by_Quantity version '1.0.0' define private Multiply_Quantity_by_Quantity: 3.0 '1' * 2.0 '1' @@ -1076,7 +1076,7 @@ library Multiply_Quantity_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -1090,7 +1090,7 @@ library Multiply_Quantity_by_Quantity version '1.0.0' [TestMethod] public void Multiply_Quantity_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Quantity_by_Null version '1.0.0' define private Multiply_Quantity_by_Null: 3.0 '1' * null @@ -1135,7 +1135,7 @@ library Multiply_Quantity_by_Null version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -1145,7 +1145,7 @@ library Multiply_Quantity_by_Null version '1.0.0' [TestMethod] public void Multiply_Null_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Multiply_Null_by_Quantity version '1.0.0' define private Multiply_Null_by_Quantity: null * 3.0 '1' @@ -1190,7 +1190,7 @@ library Multiply_Null_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(multiply); + var lambda = ToFluentElmToolkit().Lambda(multiply); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); diff --git a/Cql/CqlToElmTests/NotEqualTest.cs b/Cql/CqlToElmTests/(tests)/NotEqualTest.cs similarity index 94% rename from Cql/CqlToElmTests/NotEqualTest.cs rename to Cql/CqlToElmTests/(tests)/NotEqualTest.cs index 2999a5577..532673399 100644 --- a/Cql/CqlToElmTests/NotEqualTest.cs +++ b/Cql/CqlToElmTests/(tests)/NotEqualTest.cs @@ -11,7 +11,7 @@ public class NotEqualTest : Base [TestMethod] public void Integer_NotEquals_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_NotEquals_Integer: 1 != 2 @@ -56,7 +56,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -67,7 +67,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_NotEquals_Integer_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_NotEquals_Integer_False: 1 != 1 @@ -112,7 +112,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -123,7 +123,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_NotEquals_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_NotEquals_Long: 1 != 2L @@ -168,7 +168,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -179,7 +179,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_NotEquals_Decimal_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_NotEquals_Decimal_False: 1 != 1.0 @@ -224,7 +224,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -236,7 +236,7 @@ library EqualsTest version '1.0.0' public void Integer_NotEquals_Quantity() { // 1 converts to 1.0 '1' and '1' units are equal to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_NotEquals_Quantity: 1 != 2.0 'g' @@ -281,7 +281,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -292,7 +292,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_NotEquals_Quantity_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_NotEquals_Quantity_False: 1 != 1.0 '1' @@ -337,7 +337,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -348,7 +348,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_NotEquals_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("1 != null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("1 != null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -356,7 +356,7 @@ public void Integer_NotEquals_Null() [TestMethod] public void Null_NotEquals_Integer() { - var library = CreateCqlApi().MakeLibraryFromExpression("null != 1"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null != 1"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -368,7 +368,7 @@ public void Null_NotEquals_Integer() [TestMethod] public void Long_NotEquals_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_NotEquals_Long: 1L != 2L @@ -413,7 +413,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -424,7 +424,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_NotEquals_Long_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_NotEquals_Long_False: 1L != 1L @@ -469,7 +469,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -480,7 +480,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_NotEquals_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_NotEquals_Long: 1L != 2 @@ -525,7 +525,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -536,7 +536,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_NotEquals_Decimal_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_DoesNotEqual_Decimal: 1L != 1.0 @@ -581,7 +581,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -593,7 +593,7 @@ library EqualsTest version '1.0.0' public void Long_NotEquals_Quantity() { // 1L converts to 1.0 '1' and '1' units are equal to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_NotEquals_Quantity: 1L != 2.0 'g' @@ -638,7 +638,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -649,7 +649,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_DoesNotEqual_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_DoesNotEqual_Quantity: 1L != 1.0 '1' @@ -694,7 +694,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -705,7 +705,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_NotEquals_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("1L != null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("1L != null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -713,7 +713,7 @@ public void Long_NotEquals_Null() [TestMethod] public void Null_NotEquals_Long() { - var library = CreateCqlApi().MakeLibraryFromExpression("null != 1L"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null != 1L"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -725,7 +725,7 @@ public void Null_NotEquals_Long() [TestMethod] public void Decimal_NotEquals_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_NotEquals_Decimal: 1.0 != 2.0 @@ -770,7 +770,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -781,7 +781,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_NotEquals_Decimal_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_NotEquals_Decimal_False: 1.0 != 1.0 @@ -826,7 +826,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -837,7 +837,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_NotEquals_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_NotEquals_Decimal: 1.0 != 2 @@ -882,7 +882,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -893,7 +893,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_NotEquals_Long_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_DoesNotEqual_Decimal: 2.0 != 2L @@ -938,7 +938,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -950,7 +950,7 @@ library EqualsTest version '1.0.0' public void Decimal_NotEquals_Quantity() { // 1.0 converts to 1.0 '1' and '1' units are equal to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_NotEquals_Quantity: 1.0 != 2.0 'g' @@ -995,7 +995,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1006,7 +1006,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_DoesNotEqual_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_DoesNotEqual_Quantity: 1.0 != 1.0 '1' @@ -1051,7 +1051,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1062,7 +1062,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_NotEquals_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("1.0 != null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("1.0 != null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -1070,7 +1070,7 @@ public void Decimal_NotEquals_Null() [TestMethod] public void Null_NotEquals_Decimal() { - var library = CreateCqlApi().MakeLibraryFromExpression("null != 1.0"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null != 1.0"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); @@ -1083,7 +1083,7 @@ public void Null_NotEquals_Decimal() [TestMethod] public void Quantity_NotEquals_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_NotEquals_Quantity: 1.0 '1' != 1.01 '1' @@ -1128,7 +1128,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1139,7 +1139,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_NotEquals_Quantity_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_NotEquals_Quantity_False: 1.0 '1' != 1.0 '1' @@ -1184,7 +1184,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1195,7 +1195,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_NotEquals_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_NotEquals_Quantity: 1.0 '1' != 2 @@ -1240,7 +1240,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1251,7 +1251,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_NotEquals_Long_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_DoesNotEqual_Quantity: 2.0 '1' != 2L @@ -1296,7 +1296,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1308,7 +1308,7 @@ library EqualsTest version '1.0.0' public void Quantity_NotEquals_Decimal() { // 1.0 converts to 1.0 '1' and '1' units are equal to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_NotEquals_Decimal: 1.0 'g' != 2.0 @@ -1353,7 +1353,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1364,7 +1364,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_DoesNotEqual_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_DoesNotEqual_Quantity: 1.0 != 1.0 '1' @@ -1409,7 +1409,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1420,7 +1420,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_NotEquals_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("1.0 '1' != null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("1.0 '1' != null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -1428,7 +1428,7 @@ public void Quantity_NotEquals_Null() [TestMethod] public void Null_NotEquals_Quantity() { - var library = CreateCqlApi().MakeLibraryFromExpression("null != 1.0 '1'"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null != 1.0 '1'"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -1439,7 +1439,7 @@ public void Null_NotEquals_Quantity() [TestMethod] public void String_NotEquals_String() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private String_NotEquals_String: 'hello' != 'world' @@ -1484,7 +1484,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}String", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(equal); + var lambda = ToFluentElmToolkit().Lambda(equal); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1495,7 +1495,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void String_NotEquals_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("'hello' != null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("'hello' != null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -1503,7 +1503,7 @@ public void String_NotEquals_Null() [TestMethod] public void Null_NotEquals_String() { - var library = CreateCqlApi().MakeLibraryFromExpression("null != 'hello'"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null != 'hello'"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertNullResult(equal); } @@ -1511,7 +1511,7 @@ public void Null_NotEquals_String() [TestMethod] public void Tuple_Equal_Tuple_Null_Equals_NotNull() { - var lib = CreateCqlApi().MakeLibraryFromExpression("{ x: 1, y: null } = { x: 1, y: 2 }"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("{ x: 1, y: null } = { x: 1, y: 2 }"); var equal = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var eq = Run(equal, lib); eq.Should().BeNull(); @@ -1520,7 +1520,7 @@ public void Tuple_Equal_Tuple_Null_Equals_NotNull() [TestMethod] public void Tuple_Equal_Tuple_Null_Equals_Null() { - var lib = CreateCqlApi().MakeLibraryFromExpression("{ x: 1, y: null } = { x: 1, y: null }"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("{ x: 1, y: null } = { x: 1, y: null }"); var equal = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var eq = Run(equal, lib); eq.Should().BeTrue(); diff --git a/Cql/CqlToElmTests/NotEquivalentTest.cs b/Cql/CqlToElmTests/(tests)/NotEquivalentTest.cs similarity index 94% rename from Cql/CqlToElmTests/NotEquivalentTest.cs rename to Cql/CqlToElmTests/(tests)/NotEquivalentTest.cs index 75177ba40..f1919de43 100644 --- a/Cql/CqlToElmTests/NotEquivalentTest.cs +++ b/Cql/CqlToElmTests/(tests)/NotEquivalentTest.cs @@ -11,7 +11,7 @@ public class NotEquivalentTest : Base [TestMethod] public void Integer_NotEquivalentTo_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_NotEquivalentTo_Integer: 1 !~ 2 @@ -58,7 +58,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -69,7 +69,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_NotEquivalentTo_Integer_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_NotEquivalentTo_Integer_False: 1 !~ 1 @@ -116,7 +116,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -127,7 +127,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_NotEquivalentTo_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_NotEquivalentTo_Long: 1 !~ 2L @@ -173,7 +173,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -184,7 +184,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_NotEquivalentTo_Decimal_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_NotEquivalentTo_Decimal_False: 1 !~ 1.0 @@ -230,7 +230,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -242,7 +242,7 @@ library EqualsTest version '1.0.0' public void Integer_NotEquivalentTo_Quantity() { // 1 converts to 1.0 '1' and '1' units are equivalent to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_NotEquivalentTo_Quantity: 1 !~ 2.0 'g' @@ -288,7 +288,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -299,7 +299,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_NotEquivalentTo_Quantity_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Integer_NotEquivalentTo_Quantity_False: 1 !~ 1.0 '1' @@ -345,7 +345,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -356,7 +356,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Integer_NotEquivalentTo_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("1 !~ null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("1 !~ null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, true); } @@ -364,7 +364,7 @@ public void Integer_NotEquivalentTo_Null() [TestMethod] public void Null_NotEquivalentTo_Integer() { - var library = CreateCqlApi().MakeLibraryFromExpression("null !~ 1"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null !~ 1"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, true); } @@ -376,7 +376,7 @@ public void Null_NotEquivalentTo_Integer() [TestMethod] public void Long_NotEquivalentTo_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_NotEquivalentTo_Long: 1L !~ 2L @@ -424,7 +424,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -435,7 +435,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_NotEquivalentTo_Long_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_NotEquivalentTo_Long_False: 1L !~ 1L @@ -482,7 +482,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -493,7 +493,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_NotEquivalentTo_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_NotEquivalentTo_Long: 1L !~ 2 @@ -540,7 +540,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -551,7 +551,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_NotEquivalentTo_Decimal_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_DoesNotEqual_Decimal: 1L !~ 1.0 @@ -598,7 +598,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -610,7 +610,7 @@ library EqualsTest version '1.0.0' public void Long_NotEquivalentTo_Quantity() { // 1L converts to 1.0 '1' and '1' units are equivalent to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_NotEquivalentTo_Quantity: 1L !~ 2.0 'g' @@ -656,7 +656,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -667,7 +667,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_DoesNotEqual_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Long_DoesNotEqual_Quantity: 1L !~ 1.0 '1' @@ -713,7 +713,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -724,7 +724,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Long_NotEquivalentTo_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("1L !~ null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("1L !~ null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, true); } @@ -732,7 +732,7 @@ public void Long_NotEquivalentTo_Null() [TestMethod] public void Null_NotEquivalentTo_Long() { - var library = CreateCqlApi().MakeLibraryFromExpression("null !~ 1L"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null !~ 1L"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, true); } @@ -744,7 +744,7 @@ public void Null_NotEquivalentTo_Long() [TestMethod] public void Decimal_NotEquivalentTo_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_NotEquivalentTo_Decimal: 1.0 !~ 2.0 @@ -791,7 +791,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -802,7 +802,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_NotEquivalentTo_Decimal_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_NotEquivalentTo_Decimal_False: 1.0 !~ 1.0 @@ -849,7 +849,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -860,7 +860,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_NotEquivalentTo_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_NotEquivalentTo_Decimal: 1.0 !~ 2 @@ -907,7 +907,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -918,7 +918,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_NotEquivalentTo_Long_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_DoesNotEqual_Decimal: 2.0 !~ 2L @@ -965,7 +965,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -977,7 +977,7 @@ library EqualsTest version '1.0.0' public void Decimal_NotEquivalentTo_Quantity() { // 1.0 converts to 1.0 '1' and '1' units are equivalent to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_NotEquivalentTo_Quantity: 1.0 !~ 2.0 'g' @@ -1024,7 +1024,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1035,7 +1035,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_DoesNotEqual_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Decimal_DoesNotEqual_Quantity: 1.0 !~ 1.0 '1' @@ -1082,7 +1082,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1093,7 +1093,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Decimal_NotEquivalentTo_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("1.0 !~ null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("1.0 !~ null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, true); } @@ -1101,7 +1101,7 @@ public void Decimal_NotEquivalentTo_Null() [TestMethod] public void Null_NotEquivalentTo_Decimal() { - var library = CreateCqlApi().MakeLibraryFromExpression("null !~ 1.0"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null !~ 1.0"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, true); } @@ -1113,7 +1113,7 @@ public void Null_NotEquivalentTo_Decimal() [TestMethod] public void Quantity_NotEquivalentTo_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_NotEquivalentTo_Quantity: 1.0 '1' !~ 2 '1' @@ -1160,7 +1160,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1171,7 +1171,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_NotEquivalentTo_Quantity_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_NotEquivalentTo_Quantity_False: 1.0 '1' !~ 1.0 '1' @@ -1218,7 +1218,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1229,7 +1229,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_NotEquivalentTo_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_NotEquivalentTo_Quantity: 1.0 '1' !~ 2 @@ -1276,7 +1276,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1287,7 +1287,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_NotEquivalentTo_Long_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_DoesNotEqual_Quantity: 2.0 '1' !~ 2L @@ -1334,7 +1334,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1346,7 +1346,7 @@ library EqualsTest version '1.0.0' public void Quantity_NotEquivalentTo_Decimal() { // 1.0 converts to 1.0 '1' and '1' units are equivalent to all units - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_NotEquivalentTo_Decimal: 1.0 'g' !~ 2.0 @@ -1393,7 +1393,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1404,7 +1404,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_DoesNotEqual_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private Quantity_DoesNotEqual_Quantity: 1.0 !~ 1.0 '1' @@ -1451,7 +1451,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1462,7 +1462,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void Quantity_NotEquivalentTo_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("1.0 '1' !~ null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("1.0 '1' !~ null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, true); } @@ -1470,7 +1470,7 @@ public void Quantity_NotEquivalentTo_Null() [TestMethod] public void Null_NotEquivalentTo_Quantity() { - var library = CreateCqlApi().MakeLibraryFromExpression("null !~ 1.0 '1'"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null !~ 1.0 '1'"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, true); } @@ -1481,7 +1481,7 @@ public void Null_NotEquivalentTo_Quantity() [TestMethod] public void String_NotEquivalentTo_String() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EqualsTest version '1.0.0' define private String_NotEquivalentTo_String: 'hello' !~ 'world' @@ -1528,7 +1528,7 @@ library EqualsTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}String", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -1539,7 +1539,7 @@ library EqualsTest version '1.0.0' [TestMethod] public void String_NotEquivalentTo_Null() { - var library = CreateCqlApi().MakeLibraryFromExpression("'hello' !~ null"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("'hello' !~ null"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, true); } @@ -1547,7 +1547,7 @@ public void String_NotEquivalentTo_Null() [TestMethod] public void Null_NotEquivalentTo_String() { - var library = CreateCqlApi().MakeLibraryFromExpression("null !~ 'hello'"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("null !~ 'hello'"); var equal = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); AssertResult(equal, true); } diff --git a/Cql/CqlToElmTests/NotTest.cs b/Cql/CqlToElmTests/(tests)/NotTest.cs similarity index 93% rename from Cql/CqlToElmTests/NotTest.cs rename to Cql/CqlToElmTests/(tests)/NotTest.cs index 8fd9554a8..e0cb45a01 100644 --- a/Cql/CqlToElmTests/NotTest.cs +++ b/Cql/CqlToElmTests/(tests)/NotTest.cs @@ -9,7 +9,7 @@ public class NotTest : Base [TestMethod] public void Not_True() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library NotTest version '1.0.0' define private Not_True: not true @@ -44,7 +44,7 @@ library NotTest version '1.0.0' } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -55,7 +55,7 @@ library NotTest version '1.0.0' [TestMethod] public void Not_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library NotTest version '1.0.0' define private Not_False: not false @@ -89,7 +89,7 @@ library NotTest version '1.0.0' } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -100,7 +100,7 @@ library NotTest version '1.0.0' [TestMethod] public void Not_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library NotTest version '1.0.0' define private Not_Null: not null @@ -134,7 +134,7 @@ library NotTest version '1.0.0' } - var lambda = CreateElmApi().Lambda(not); + var lambda = ToFluentElmToolkit().Lambda(not); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -143,7 +143,7 @@ library NotTest version '1.0.0' [TestMethod] public void Not_1() => - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library NotTest version '1.0.0' define private Not_1: not 1 diff --git a/Cql/CqlToElmTests/OrTest.cs b/Cql/CqlToElmTests/(tests)/OrTest.cs similarity index 95% rename from Cql/CqlToElmTests/OrTest.cs rename to Cql/CqlToElmTests/(tests)/OrTest.cs index 93f280719..d3b4711c5 100644 --- a/Cql/CqlToElmTests/OrTest.cs +++ b/Cql/CqlToElmTests/(tests)/OrTest.cs @@ -9,7 +9,7 @@ public class OrTest : Base [TestMethod] public void True_Or_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library OrTest version '1.0.0' define private True_Or_False: true or false @@ -54,7 +54,7 @@ library OrTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(or); + var lambda = ToFluentElmToolkit().Lambda(or); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -65,7 +65,7 @@ library OrTest version '1.0.0' [TestMethod] public void True_Or_True() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library OrTest version '1.0.0' define private True_Or_True: true or true @@ -110,7 +110,7 @@ library OrTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(or); + var lambda = ToFluentElmToolkit().Lambda(or); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -121,7 +121,7 @@ library OrTest version '1.0.0' [TestMethod] public void False_Or_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library OrTest version '1.0.0' define private False_Or_False: false or false @@ -166,7 +166,7 @@ library OrTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(or); + var lambda = ToFluentElmToolkit().Lambda(or); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -177,7 +177,7 @@ library OrTest version '1.0.0' [TestMethod] public void True_Or_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library OrTest version '1.0.0' define private True_Or_Null: true or null @@ -222,7 +222,7 @@ library OrTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(or); + var lambda = ToFluentElmToolkit().Lambda(or); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -233,7 +233,7 @@ library OrTest version '1.0.0' [TestMethod] public void Null_Or_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library OrTest version '1.0.0' define private Null_Or_False: null or false @@ -278,7 +278,7 @@ library OrTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(or); + var lambda = ToFluentElmToolkit().Lambda(or); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -289,7 +289,7 @@ library OrTest version '1.0.0' [TestMethod] public void Null_Or_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library OrTest version '1.0.0' define private Null_Or_Null: null or null @@ -334,7 +334,7 @@ library OrTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(or); + var lambda = ToFluentElmToolkit().Lambda(or); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -344,7 +344,7 @@ library OrTest version '1.0.0' [TestMethod] public void True_Or_1() { - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library OrTest version '1.0.0' define private True_Or_1: true or 1 diff --git a/Cql/CqlToElmTests/OrderingTest.cs b/Cql/CqlToElmTests/(tests)/OrderingTest.cs similarity index 89% rename from Cql/CqlToElmTests/OrderingTest.cs rename to Cql/CqlToElmTests/(tests)/OrderingTest.cs index 5b3a90c39..9d41aa8fd 100644 --- a/Cql/CqlToElmTests/OrderingTest.cs +++ b/Cql/CqlToElmTests/(tests)/OrderingTest.cs @@ -8,7 +8,7 @@ public class OrderingTest : Base [TestMethod] public void Order_Simple() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Test version '1.0.0' define a: b define b: true """); @@ -20,7 +20,7 @@ public void Order_Simple() [TestMethod] public void Order_Indirection_2() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Test version '1.0.0' define a: b define b: c define c: true @@ -34,7 +34,7 @@ public void Order_Indirection_2() [TestMethod] public void Function_Simple() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Test version '1.0.0' define a: b() define function b(): true """); @@ -45,7 +45,7 @@ define function b(): true [TestMethod] public void Function_Indirection_2() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Test version '1.0.0' define a: b() define function b(): c() define function c(): true diff --git a/Cql/CqlToElmTests/OverlapsTest.cs b/Cql/CqlToElmTests/(tests)/OverlapsTest.cs similarity index 95% rename from Cql/CqlToElmTests/OverlapsTest.cs rename to Cql/CqlToElmTests/(tests)/OverlapsTest.cs index abced2c1c..7b55cffab 100644 --- a/Cql/CqlToElmTests/OverlapsTest.cs +++ b/Cql/CqlToElmTests/(tests)/OverlapsTest.cs @@ -8,7 +8,7 @@ public class OverlapsTest : Base [TestMethod] public void Overlaps() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library OverlapsTest version '1.0.0' define private Overlaps: Interval[0, 4] overlaps Interval[1, 4] @@ -37,7 +37,7 @@ library OverlapsTest version '1.0.0' [TestMethod] public void Overlaps_Before() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library OverlapsTest version '1.0.0' define private Overlaps_Before: Interval[0, 4] overlaps before Interval[1, 4] @@ -66,7 +66,7 @@ library OverlapsTest version '1.0.0' [TestMethod] public void Overlaps_After() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library OverlapsTest version '1.0.0' define private Overlaps_After: Interval[0, 4] overlaps after Interval[1, 4] @@ -95,7 +95,7 @@ library OverlapsTest version '1.0.0' [TestMethod] public void Overlaps_Is_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library OverlapsTest version '1.0.0' define private Overlaps_Is_Null: Interval[6, 10] overlaps (null as Interval) @@ -123,7 +123,7 @@ library OverlapsTest version '1.0.0' [TestMethod] public void Overlaps_After_Day() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library OverlapsTest version '1.0.0' define private Overlaps_After_Day: Interval[@2023-03-01, @2023-06-01] overlaps after month of Interval[@2023-01-01, @2023-03-01] @@ -152,7 +152,7 @@ library OverlapsTest version '1.0.0' [TestMethod] public void Overlaps_Day() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library OverlapsTest version '1.0.0' define private Overlaps_Day: Interval[@2023-01-01, @2023-06-01] overlaps month of Interval[@2023-07-01, @2023-10-01] diff --git a/Cql/CqlToElmTests/PointFromTest.cs b/Cql/CqlToElmTests/(tests)/PointFromTest.cs similarity index 92% rename from Cql/CqlToElmTests/PointFromTest.cs rename to Cql/CqlToElmTests/(tests)/PointFromTest.cs index a86fe8e68..b94a76a2a 100644 --- a/Cql/CqlToElmTests/PointFromTest.cs +++ b/Cql/CqlToElmTests/(tests)/PointFromTest.cs @@ -9,7 +9,7 @@ public class PointFromTest : Base [TestMethod] public void Point_From_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library PointFromTest version '1.0.0' define private Point_From_Integers: point from Interval[4,4] @@ -30,7 +30,7 @@ library PointFromTest version '1.0.0' var interval = (Interval)pointFrom.operand; AssertIntervalType(interval.resultTypeSpecifier, $"{{{SystemUri}}}Integer"); - var lambda = CreateElmApi().Lambda(pointFrom); + var lambda = ToFluentElmToolkit().Lambda(pointFrom); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); @@ -43,7 +43,7 @@ library PointFromTest version '1.0.0' [TestMethod] public void Point_From_Integer_Closed() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library PointFromTest version '1.0.0' define private Point_From_Integers: point from Interval[4,5) @@ -64,7 +64,7 @@ library PointFromTest version '1.0.0' var interval = (Interval)pointFrom.operand; AssertIntervalType(interval.resultTypeSpecifier, $"{{{SystemUri}}}Integer"); - var lambda = CreateElmApi().Lambda(pointFrom); + var lambda = ToFluentElmToolkit().Lambda(pointFrom); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); @@ -78,7 +78,7 @@ library PointFromTest version '1.0.0' [TestMethod] public void Point_From_Integers_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library PointFromTest version '1.0.0' define private Point_From_Integers_Null: point from (null as Interval) @@ -100,7 +100,7 @@ library PointFromTest version '1.0.0' Assert.IsInstanceOfType(@as.operand, typeof(Null)); AssertIntervalType(@as.resultTypeSpecifier, $"{{{SystemUri}}}Integer"); - var lambda = CreateElmApi().Lambda(pointFrom); + var lambda = ToFluentElmToolkit().Lambda(pointFrom); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); @@ -111,7 +111,7 @@ library PointFromTest version '1.0.0' [TestMethod] public void Point_From_Integers_Error() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library PointFromTest version '1.0.0' define private Point_From_Integers_Error: point from Interval[1,4] @@ -132,7 +132,7 @@ library PointFromTest version '1.0.0' var list = (Interval)pointFrom.operand; AssertIntervalType(list.resultTypeSpecifier, $"{{{SystemUri}}}Integer"); - var lambda = CreateElmApi().Lambda(pointFrom); + var lambda = ToFluentElmToolkit().Lambda(pointFrom); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); Assert.ThrowsException(() => dg.DynamicInvoke(ctx)); diff --git a/Cql/CqlToElmTests/PowerTest.cs b/Cql/CqlToElmTests/(tests)/PowerTest.cs similarity index 95% rename from Cql/CqlToElmTests/PowerTest.cs rename to Cql/CqlToElmTests/(tests)/PowerTest.cs index 8bc995636..36c39c0d4 100644 --- a/Cql/CqlToElmTests/PowerTest.cs +++ b/Cql/CqlToElmTests/(tests)/PowerTest.cs @@ -11,7 +11,7 @@ public class PowerTest : Base [TestMethod] public void Power_Integer_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Power_Integer_to_Integer version '1.0.0' define private Power_Integer_to_Integer: 2 ^ 3 @@ -56,7 +56,7 @@ library Power_Integer_to_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(power); + var lambda = ToFluentElmToolkit().Lambda(power); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(int?)); @@ -67,7 +67,7 @@ library Power_Integer_to_Integer version '1.0.0' [TestMethod] public void Power_Integer_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Power_Integer_to_Integer version '1.0.0' define private Power_Integer_to_Integer: 2 ^ 3L @@ -112,7 +112,7 @@ library Power_Integer_to_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(power); + var lambda = ToFluentElmToolkit().Lambda(power); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -123,7 +123,7 @@ library Power_Integer_to_Integer version '1.0.0' [TestMethod] public void Power_Integer_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Power_Integer_to_Integer version '1.0.0' define private Power_Integer_to_Integer: 2 ^ 3.0 @@ -168,7 +168,7 @@ library Power_Integer_to_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(power); + var lambda = ToFluentElmToolkit().Lambda(power); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -179,7 +179,7 @@ library Power_Integer_to_Integer version '1.0.0' [TestMethod] public void Power_Integer_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Power_Integer_by_Null version '1.0.0' define private Product: 1 ^ null @@ -223,7 +223,7 @@ library Power_Integer_by_Null version '1.0.0' Assert.IsNotNull(lhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Integer", lhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(power); + var lambda = ToFluentElmToolkit().Lambda(power); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -233,7 +233,7 @@ library Power_Integer_by_Null version '1.0.0' [TestMethod] public void Power_Null_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Power_Integer_by_Null version '1.0.0' define private Product: null ^ 1 @@ -277,7 +277,7 @@ library Power_Integer_by_Null version '1.0.0' Assert.IsNotNull(rhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(power); + var lambda = ToFluentElmToolkit().Lambda(power); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -291,7 +291,7 @@ library Power_Integer_by_Null version '1.0.0' [TestMethod] public void Power_Long_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Power_Long_by_Integer version '1.0.0' define private Power_Integer_to_Integer: -2L ^ 3 @@ -336,7 +336,7 @@ library Power_Long_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(power); + var lambda = ToFluentElmToolkit().Lambda(power); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -347,7 +347,7 @@ library Power_Long_by_Integer version '1.0.0' [TestMethod] public void Power_Long_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Power_Long_by_Integer version '1.0.0' define private Power_Integer_to_Integer: -2L ^ 3L @@ -392,7 +392,7 @@ library Power_Long_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(power); + var lambda = ToFluentElmToolkit().Lambda(power); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -403,7 +403,7 @@ library Power_Long_by_Integer version '1.0.0' [TestMethod] public void Power_Long_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Power_Long_by_Integer version '1.0.0' define private Power_Integer_to_Integer: -2L ^ 3.0 @@ -448,7 +448,7 @@ library Power_Long_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(power); + var lambda = ToFluentElmToolkit().Lambda(power); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -459,7 +459,7 @@ library Power_Long_by_Integer version '1.0.0' [TestMethod] public void Power_Long_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Power_Long_by_Null version '1.0.0' define private Product: 1L ^ null @@ -503,7 +503,7 @@ library Power_Long_by_Null version '1.0.0' Assert.IsNotNull(lhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Long", lhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(power); + var lambda = ToFluentElmToolkit().Lambda(power); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -513,7 +513,7 @@ library Power_Long_by_Null version '1.0.0' [TestMethod] public void Power_Null_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Power_Integer_by_Null version '1.0.0' define private Product: null ^ 1L @@ -557,7 +557,7 @@ library Power_Integer_by_Null version '1.0.0' Assert.IsNotNull(rhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(power); + var lambda = ToFluentElmToolkit().Lambda(power); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -571,7 +571,7 @@ library Power_Integer_by_Null version '1.0.0' [TestMethod] public void Power_Decimal_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Power_Decimal_by_Integer version '1.0.0' define private Power_Integer_to_Integer: 0.0 ^ 3 @@ -616,7 +616,7 @@ library Power_Decimal_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(power); + var lambda = ToFluentElmToolkit().Lambda(power); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -627,7 +627,7 @@ library Power_Decimal_by_Integer version '1.0.0' [TestMethod] public void Power_Decimal_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Power_Decimal_by_Integer version '1.0.0' define private Power_Integer_to_Integer: 5.0 ^ 5L @@ -672,7 +672,7 @@ library Power_Decimal_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(power); + var lambda = ToFluentElmToolkit().Lambda(power); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -683,7 +683,7 @@ library Power_Decimal_by_Integer version '1.0.0' [TestMethod] public void Power_Decimal_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Power_Decimal_by_Integer version '1.0.0' define private Power_Integer_to_Integer: -10.0 ^ 10.0 @@ -728,7 +728,7 @@ library Power_Decimal_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(power); + var lambda = ToFluentElmToolkit().Lambda(power); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -739,7 +739,7 @@ library Power_Decimal_by_Integer version '1.0.0' [TestMethod] public void Power_Decimal_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Power_Decimal_by_Null version '1.0.0' define private Product: 1.0 ^ null @@ -783,7 +783,7 @@ library Power_Decimal_by_Null version '1.0.0' Assert.IsNotNull(lhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", lhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(power); + var lambda = ToFluentElmToolkit().Lambda(power); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -793,7 +793,7 @@ library Power_Decimal_by_Null version '1.0.0' [TestMethod] public void Power_Null_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Power_Integer_by_Null version '1.0.0' define private Product: null ^ 1.0 @@ -837,7 +837,7 @@ library Power_Integer_by_Null version '1.0.0' Assert.IsNotNull(rhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(power); + var lambda = ToFluentElmToolkit().Lambda(power); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); diff --git a/Cql/CqlToElmTests/PredecessorTest.cs b/Cql/CqlToElmTests/(tests)/PredecessorTest.cs similarity index 91% rename from Cql/CqlToElmTests/PredecessorTest.cs rename to Cql/CqlToElmTests/(tests)/PredecessorTest.cs index 2cba10b3e..94b46d4a3 100644 --- a/Cql/CqlToElmTests/PredecessorTest.cs +++ b/Cql/CqlToElmTests/(tests)/PredecessorTest.cs @@ -10,7 +10,7 @@ public class PredecessorTest : Base [TestMethod] public void Predecessor_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library PointFromTest version '1.0.0' define private Point_From_Integers: predecessor of 2 @@ -30,7 +30,7 @@ library PointFromTest version '1.0.0' Assert.IsInstanceOfType(predecessor.operand, typeof(Literal)); - var lambda = CreateElmApi().Lambda(predecessor); + var lambda = ToFluentElmToolkit().Lambda(predecessor); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); @@ -43,7 +43,7 @@ library PointFromTest version '1.0.0' [TestMethod] public void Predecessor_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library PointFromTest version '1.0.0' define private Point_From_Integers: predecessor of (null as Integer) @@ -63,7 +63,7 @@ library PointFromTest version '1.0.0' Assert.IsInstanceOfType(predecessor.operand, typeof(As)); - var lambda = CreateElmApi().Lambda(predecessor); + var lambda = ToFluentElmToolkit().Lambda(predecessor); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); diff --git a/Cql/CqlToElmTests/QueryTest.cs b/Cql/CqlToElmTests/(tests)/QueryTest.cs similarity index 89% rename from Cql/CqlToElmTests/QueryTest.cs rename to Cql/CqlToElmTests/(tests)/QueryTest.cs index 3041ffec4..14ca52afc 100644 --- a/Cql/CqlToElmTests/QueryTest.cs +++ b/Cql/CqlToElmTests/(tests)/QueryTest.cs @@ -8,7 +8,7 @@ public class QueryTest : Base [TestMethod] public void String_lengths() { - var lib = CreateCqlApi().MakeLibraryFromExpression("from ({'hello', 'world'}) str return Length(str)"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("from ({'hello', 'world'}) str return Length(str)"); var query = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); query.Should().HaveType(SystemTypes.IntegerType.ToListType()); } @@ -17,7 +17,7 @@ public void String_lengths() [TestMethod] public void Sort_asc() { - var lib = CreateCqlApi().MakeLibraryFromExpression("({4, 5, 1, 6, 2, 1}) sL sort asc"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("({4, 5, 1, 6, 2, 1}) sL sort asc"); var query = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); query.Should().HaveType(SystemTypes.IntegerType.ToListType()); @@ -26,7 +26,7 @@ public void Sort_asc() [TestMethod] public void Scalar_source() { - var lib = CreateCqlApi().MakeLibraryFromExpression("from (true) t return t and false"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("from (true) t return t and false"); var query = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); query.Should().HaveType(SystemTypes.BooleanType); query.@return.Should().HaveType(SystemTypes.BooleanType); @@ -34,7 +34,7 @@ public void Scalar_source() [TestMethod] public void Vector_source() { - var lib = CreateCqlApi().MakeLibraryFromExpression("from ({ true, false }) t return t and false"); + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression("from ({ true, false }) t return t and false"); var query = lib.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); query.Should().HaveType(SystemTypes.BooleanType.ToListType()); query.@return.Should().HaveType(SystemTypes.BooleanType.ToListType()); @@ -42,7 +42,7 @@ public void Vector_source() [TestMethod] public void Relationship_with_scalar_sources() { - var lib = CreateCqlApi().MakeLibraryFromExpression(""" + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression(""" from(true) t with(false) f such that t != f @@ -54,7 +54,7 @@ where t [TestMethod] public void Relationship_with_bad_identifier() { - CreateCqlApi().MakeLibrary($""" + CreateFluentCqlToolkit().MakeLibrary($""" library Test version '1.0.0' define f: from (true) t @@ -68,7 +68,7 @@ where t is true [TestMethod] public void Multi_scalar_source() { - var lib = CreateCqlApi().MakeLibraryFromExpression(""" + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression(""" from (1) Num1, (2) Num2 @@ -85,7 +85,7 @@ public void Multi_scalar_source() [TestMethod] public void Multi_vector_source() { - var lib = CreateCqlApi().MakeLibraryFromExpression(""" + var lib = CreateFluentCqlToolkit().MakeLibraryFromExpression(""" from ( { 1, 2 } ) Num1, ( { 3, 4 } ) Num2 @@ -102,7 +102,7 @@ public void Multi_vector_source() [TestMethod] public void Sort_Calls_Function() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Sort_Calls_Fluent version '1.0.0' define function foo(): 1 @@ -130,7 +130,7 @@ define function foo(): 1 [TestMethod] public void Sort_Calls_Fluent() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Sort_Calls_Fluent version '1.0.0' define fluent function foo(i Integer): i @@ -160,7 +160,7 @@ define fluent function foo(i Integer): i [TestMethod] public void Sort_Prefers_Fluent() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Sort_Calls_Fluent version '1.0.0' define fluent function foo(i Integer): i @@ -190,7 +190,7 @@ define function foo(): 1 [TestMethod] public void Let() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Let version '1.0.0' define q: from @@ -209,7 +209,7 @@ where x > 0 public void Let_Redefinition() { // TODO: make this optionally fail w/ config options - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Let version '1.0.0' define q: from @@ -225,7 +225,7 @@ public void Let_Redefine_Operand() { // TODO: make this optionally fail w/ config options - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Let version '1.0.0' define function q(x Integer): from @@ -240,7 +240,7 @@ where x > 0 [TestMethod] public void Claims_Query() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Claims version '1.0.0' using FHIR version '4.0.1' @@ -259,7 +259,7 @@ such that careTeam.provider is FHIR.Reference [TestMethod] public void Return_Query() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Claims version '1.0.0' using FHIR version '4.0.1' @@ -276,7 +276,7 @@ library Claims version '1.0.0' [TestMethod] public void Aggregate_Factorial() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Claims version '1.0.0' using FHIR version '4.0.1' @@ -300,7 +300,7 @@ library Claims version '1.0.0' [TestMethod] public void Aggregate_Factorial_Distinct() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Claims version '1.0.0' using FHIR version '4.0.1' @@ -323,7 +323,7 @@ library Claims version '1.0.0' [TestMethod] public void Aggregate_Factorial_No_Starting() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Claims version '1.0.0' using FHIR version '4.0.1' @@ -346,7 +346,7 @@ library Claims version '1.0.0' [TestMethod] public void Aggregate_List_Accumulator() { - var lib = CreateCqlApi().MakeLibrary(""" + var lib = CreateFluentCqlToolkit().MakeLibrary(""" library Claims version '1.0.0' using FHIR version '4.0.1' diff --git a/Cql/CqlToElmTests/RefTest.cs b/Cql/CqlToElmTests/(tests)/RefTest.cs similarity index 89% rename from Cql/CqlToElmTests/RefTest.cs rename to Cql/CqlToElmTests/(tests)/RefTest.cs index b37c9014b..3849083f3 100644 --- a/Cql/CqlToElmTests/RefTest.cs +++ b/Cql/CqlToElmTests/(tests)/RefTest.cs @@ -14,7 +14,7 @@ public class RefTest : Base [TestMethod] public void ValueSet_Local() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library {nameof(RefTest)} version '1.0.0' valueset "vs": 'http://xyz.com' @@ -35,7 +35,7 @@ public void ValueSet_Local() [Ignore("Will fix in https://github.com/FirelyTeam/firely-cql-sdk/issues/519")] public void CodeSystem_Local() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library {nameof(RefTest)} version '1.0.0' private codesystem CS: 'id' version 'version string' @@ -55,7 +55,7 @@ public void CodeSystem_Local() [TestMethod] public void Code_Local() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library {nameof(RefTest)} version '1.0.0' private codesystem CS: 'id' version 'version string' @@ -76,7 +76,7 @@ public void Code_Local() [TestMethod] public void Concept_Local() { - var library = CreateCqlApi().MakeLibrary($$""" + var library = CreateFluentCqlToolkit().MakeLibrary($$""" library {{nameof(RefTest)}} version '1.0.0' private codesystem CS: 'id' version 'version string' @@ -98,7 +98,7 @@ public void Concept_Local() [TestMethod] public void Parameter() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library {nameof(RefTest)} version '1.0.0' private parameter "Measurement Year" System.Integer default 2023 @@ -118,7 +118,7 @@ public void Parameter() private static T? Run(Library library, string member, Hl7.Fhir.Model.Bundle? bundle = null) { - var lambdas = CreateElmApi().ProcessLibrary(library); + var lambdas = ToFluentElmToolkit().ProcessLibrary(library); var delegates = lambdas.CompileAll(); var dg = delegates[library.GetVersionedIdentifier()!, member]; var ctx = FhirCqlContext.ForBundle(bundle, delegates: delegates); @@ -140,7 +140,7 @@ private ExpressionDef shouldDefineExpression(Library l, string name) => [TestMethod] public void Expression() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library {nameof(RefTest)} version '1.0.0' define private four: 4 @@ -161,7 +161,7 @@ public void Expression() [Ignore("Will fix in https://github.com/FirelyTeam/firely-cql-sdk/issues/397")] public void Function() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library {nameof(RefTest)} version '1.0.0' define private function double(a Decimal): a*2 @@ -181,7 +181,7 @@ define private function double(a Decimal): a*2 [TestMethod] public void FunctionIncorrectNumParam() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library {nameof(RefTest)} version '1.0.0' define private function double(a Decimal): a*2 @@ -193,7 +193,7 @@ define private function double(a Decimal): a*2 [TestMethod] public void FunctionIncorrectParam() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library {nameof(RefTest)} version '1.0.0' define private function double(a Decimal): a*2 @@ -205,23 +205,23 @@ define private function double(a Decimal): a*2 [TestMethod] public void FunctionVariableParamCount() { - var library1 = CreateCqlApi().MakeLibrary($""" + var library1 = CreateFluentCqlToolkit().MakeLibrary($""" library {nameof(RefTest)}1 version '1.0.0' define private {nameof(Function)}: Date(1) """); - var library2 = CreateCqlApi().MakeLibrary($""" + var library2 = CreateFluentCqlToolkit().MakeLibrary($""" library {nameof(RefTest)}2 version '1.0.0' define private {nameof(Function)}: Date(1,2) """); - var library3 = CreateCqlApi().MakeLibrary($""" + var library3 = CreateFluentCqlToolkit().MakeLibrary($""" library {nameof(RefTest)}3 version '1.0.0' define private {nameof(Function)}: Date(1,2,3) """); - var library4 = CreateCqlApi().MakeLibrary($""" + var library4 = CreateFluentCqlToolkit().MakeLibrary($""" library {nameof(RefTest)}4 version '1.0.0' define private {nameof(Function)}: Date(1,2,3,4) """, "Could not resolve *"); - var library5 = CreateCqlApi().MakeLibrary($""" + var library5 = CreateFluentCqlToolkit().MakeLibrary($""" library {nameof(RefTest)}5 version '1.0.0' define private {nameof(Function)}: Date() """, "Could not resolve *"); @@ -230,7 +230,7 @@ public void FunctionVariableParamCount() [TestMethod] public void InvokeParameter() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' parameter x default 'bla' @@ -242,7 +242,7 @@ library BareMinimum version '0.0.1' [TestMethod] public void InvokeExpression() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' define pi: 3.14 @@ -254,7 +254,7 @@ library BareMinimum version '0.0.1' [TestMethod] public void InvokeNonLocalFunction() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' include Math @@ -266,7 +266,7 @@ include Math [TestMethod] public void InvokeLibrary() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' include Math @@ -279,7 +279,7 @@ include Math [TestMethod] public void InvokeNonLocalExpression() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' include Math @@ -292,7 +292,7 @@ include Math [TestMethod] public void InvokeNonexistentFluentFunction() { - _ = CreateCqlApi().MakeLibrary($""" + _ = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' using FHIR @@ -306,7 +306,7 @@ context Patient [Ignore("Will fix in https://github.com/FirelyTeam/firely-cql-sdk/issues/397")] public void InvokeFluentFunction() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' define fluent function double(a Integer): a*2 @@ -325,7 +325,7 @@ define fluent function double(a Integer): a*2 [TestMethod] public void InvokeIntervalMember() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' define lowI: Interval[1,3].low @@ -342,7 +342,7 @@ library BareMinimum version '0.0.1' [TestMethod] public void InvokeIntervalClosedMember() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' define closed: Interval[1,3].highClosed @@ -359,7 +359,7 @@ library BareMinimum version '0.0.1' [TestMethod] public void InvokeTupleMember() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library BareMinimum version '0.0.1' define tupleMember: Tuple { name: 'Ewout' }.name @@ -376,7 +376,7 @@ library BareMinimum version '0.0.1' [TestMethod] public void InvokeNonFluentFunctionFluently() { - _ = CreateCqlApi().MakeLibrary($""" + _ = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' define function double(a Integer): a*2 @@ -387,7 +387,7 @@ define function double(a Integer): a*2 [TestMethod] public void InvokeModel() { - _ = CreateCqlApi().MakeLibrary($""" + _ = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' using FHIR @@ -398,7 +398,7 @@ library BareMinimum version '0.0.1' [TestMethod] public void InvokeQualifiedType() { - _ = CreateCqlApi().MakeLibrary($""" + _ = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' using FHIR @@ -409,7 +409,7 @@ library BareMinimum version '0.0.1' [TestMethod] public void InvokeNoMembers() { - _ = CreateCqlApi().MakeLibrary($""" + _ = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' using FHIR @@ -420,7 +420,7 @@ library BareMinimum version '0.0.1' [TestMethod] public void InvokeChoiceMembers() { - _ = CreateCqlApi().MakeLibrary($""" + _ = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' using FHIR @@ -432,7 +432,7 @@ define function choice() returns Choice : external [TestMethod] public void InvokeType() { - _ = CreateCqlApi().MakeLibrary(""" + _ = CreateFluentCqlToolkit().MakeLibrary(""" library BareMinimum version '0.0.1' using FHIR @@ -445,7 +445,7 @@ include Math [TestMethod] public void InvokeProperty() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' using FHIR @@ -467,7 +467,7 @@ context Patient [TestMethod] public void InvokeListProperty() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' using FHIR @@ -489,7 +489,7 @@ context Patient [TestMethod] public void InvokeThroughListProperty() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' using FHIR @@ -509,7 +509,7 @@ context Patient [TestMethod] public void InvokeListPropertyThroughListProperty() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' using FHIR @@ -530,7 +530,7 @@ context Patient [Ignore("Will fix in https://github.com/FirelyTeam/firely-cql-sdk/issues/397")] public void InvokeListPropertyViaFunction() { - var library = CreateCqlApi().MakeLibrary($""" + var library = CreateFluentCqlToolkit().MakeLibrary($""" library BareMinimum version '0.0.1' using FHIR diff --git a/Cql/CqlToElmTests/RetrieveTest.cs b/Cql/CqlToElmTests/(tests)/RetrieveTest.cs similarity index 91% rename from Cql/CqlToElmTests/RetrieveTest.cs rename to Cql/CqlToElmTests/(tests)/RetrieveTest.cs index af1eca365..38a2d0bef 100644 --- a/Cql/CqlToElmTests/RetrieveTest.cs +++ b/Cql/CqlToElmTests/(tests)/RetrieveTest.cs @@ -2,7 +2,8 @@ using Hl7.Cql.Fhir; using Hl7.Fhir.Model; using CqlSdkPrototype.Infrastructure; -using CqlSdkPrototype.Runtime.Extensions; +using CqlSdkPrototype.Invocation.Extensions; +using CqlSdkPrototype.Invocation.Fluent.Extensions; namespace Hl7.Cql.CqlToElm.Test { @@ -12,7 +13,7 @@ public class RetrieveTest : Base [TestMethod] public void Retrieve_AllTerms() { - var cqlApi = CreateCqlApi(); + var cqlToolkit = CreateFluentCqlToolkit(); var cqlLibraryString = CqlLibraryString.Parse(""" library RetrieveTest version '1.0.0' @@ -24,7 +25,7 @@ context Patient define private Retrieve_AllTerms: [Patient->Condition: code in "terminology"] """); - var library = cqlApi.MakeLibrary(cqlLibraryString.Cql); + var library = cqlToolkit.MakeLibrary(cqlLibraryString.Cql); Assert.IsNotNull(library.statements); Assert.AreEqual(2, library.statements.Length); Assert.IsNotNull(library.statements[1].expression.localId); @@ -96,8 +97,8 @@ context Patient } }; - using var scope = cqlApi.CreateRuntimeScope(); - var result = scope.GetLibraryDefinitionResult(FhirCqlContext.ForBundle(bundle, valueSets: valueSets), + using var librarySetInvoker = cqlToolkit.ToLibrarySetInvoker(); + var result = librarySetInvoker.GetLibraryDefinitionResult(FhirCqlContext.ForBundle(bundle, valueSets: valueSets), cqlLibraryString.VersionedLibraryIdentifier, "Retrieve_AllTerms"); var conditions = result as IEnumerable; Assert.IsNotNull(conditions); diff --git a/Cql/CqlToElmTests/SingletonTest.cs b/Cql/CqlToElmTests/(tests)/SingletonTest.cs similarity index 91% rename from Cql/CqlToElmTests/SingletonTest.cs rename to Cql/CqlToElmTests/(tests)/SingletonTest.cs index 638484a7d..08e779c7b 100644 --- a/Cql/CqlToElmTests/SingletonTest.cs +++ b/Cql/CqlToElmTests/(tests)/SingletonTest.cs @@ -9,7 +9,7 @@ public class SingletonTest : Base [TestMethod] public void Singleton_From_Integers() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library SingletonTest version '1.0.0' define private Singleton_From_Integers: singleton from { 1 } @@ -31,7 +31,7 @@ library SingletonTest version '1.0.0' AssertListType(list.resultTypeSpecifier, $"{{{SystemUri}}}Integer"); AssertList(list, new int?[] { 1 }); - var lambda = CreateElmApi().Lambda(singletonFrom); + var lambda = ToFluentElmToolkit().Lambda(singletonFrom); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); @@ -44,7 +44,7 @@ library SingletonTest version '1.0.0' [TestMethod] public void Singleton_From_Empty() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library SingletonTest version '1.0.0' define private Singleton_From_Empty: singleton from ({} as List) @@ -67,7 +67,7 @@ library SingletonTest version '1.0.0' var list = (List)@as.operand; Assert.IsInstanceOfType(@as.operand, typeof(List)); AssertList(list, Array.Empty()); // empty list typed as Any - var lambda = CreateElmApi().Lambda(singletonFrom); + var lambda = ToFluentElmToolkit().Lambda(singletonFrom); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); @@ -78,7 +78,7 @@ library SingletonTest version '1.0.0' [TestMethod] public void Singleton_From_Integers_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library SingletonTest version '1.0.0' define private Singleton_From_Integers_Null: singleton from (null as List) @@ -100,7 +100,7 @@ library SingletonTest version '1.0.0' Assert.IsInstanceOfType(@as.operand, typeof(Null)); AssertListType(@as.resultTypeSpecifier, $"{{{SystemUri}}}Integer"); - var lambda = CreateElmApi().Lambda(singletonFrom); + var lambda = ToFluentElmToolkit().Lambda(singletonFrom); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); @@ -111,7 +111,7 @@ library SingletonTest version '1.0.0' [TestMethod] public void Singleton_From_Integers_Error() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library SingletonTest version '1.0.0' define private Singleton_From_Integers_Error: singleton from { 1, 2, 3 } @@ -133,7 +133,7 @@ library SingletonTest version '1.0.0' AssertListType(list.resultTypeSpecifier, $"{{{SystemUri}}}Integer"); AssertList(list, new int?[] { 1, 2, 3 }); - var lambda = CreateElmApi().Lambda(singletonFrom); + var lambda = ToFluentElmToolkit().Lambda(singletonFrom); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); Assert.ThrowsException(() => dg.DynamicInvoke(ctx)); @@ -143,7 +143,7 @@ library SingletonTest version '1.0.0' [TestMethod] public void Singleton_From_Integer_With_List_Promotion() { - var library = CreateCqlApi(EnableListPromotion:true).MakeLibrary(""" + var library = CreateFluentCqlToolkit(EnableListPromotion:true).MakeLibrary(""" library SingletonTest version '1.0.0' define private Singleton_From_Integer_With_List_Promotion: singleton from 1 diff --git a/Cql/CqlToElmTests/SkippedTests.cs b/Cql/CqlToElmTests/(tests)/SkippedTests.cs similarity index 100% rename from Cql/CqlToElmTests/SkippedTests.cs rename to Cql/CqlToElmTests/(tests)/SkippedTests.cs diff --git a/Cql/CqlToElmTests/StartEndTest.cs b/Cql/CqlToElmTests/(tests)/StartEndTest.cs similarity index 94% rename from Cql/CqlToElmTests/StartEndTest.cs rename to Cql/CqlToElmTests/(tests)/StartEndTest.cs index 10bfd696f..e5f86ca2a 100644 --- a/Cql/CqlToElmTests/StartEndTest.cs +++ b/Cql/CqlToElmTests/(tests)/StartEndTest.cs @@ -8,7 +8,7 @@ public class StartEndTest : Base [TestMethod] public void Start_of() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library StartEndTest version '1.0.0' define private Start_of: start of Interval[1, 3] @@ -34,7 +34,7 @@ library StartEndTest version '1.0.0' [TestMethod] public void Start_of_null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library StartEndTest version '1.0.0' define private Start_of_null: start of (null as Interval) @@ -59,7 +59,7 @@ library StartEndTest version '1.0.0' [TestMethod] public void Start_of_point_null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library StartEndTest version '1.0.0' define private Start_of_point_null: start of Interval(null, 10] @@ -85,7 +85,7 @@ library StartEndTest version '1.0.0' [TestMethod] public void End_of() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EndEndTest version '1.0.0' define private End_of: end of Interval[1, 3] @@ -111,7 +111,7 @@ library EndEndTest version '1.0.0' [TestMethod] public void End_of_null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EndEndTest version '1.0.0' define private End_of_null: end of (null as Interval) @@ -136,7 +136,7 @@ library EndEndTest version '1.0.0' [TestMethod] public void End_of_point_null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library EndEndTest version '1.0.0' define private End_of_point_null: end of Interval[10, null) diff --git a/Cql/CqlToElmTests/StartsEndsTest.cs b/Cql/CqlToElmTests/(tests)/StartsEndsTest.cs similarity index 95% rename from Cql/CqlToElmTests/StartsEndsTest.cs rename to Cql/CqlToElmTests/(tests)/StartsEndsTest.cs index e11dd1021..0dfb0a032 100644 --- a/Cql/CqlToElmTests/StartsEndsTest.cs +++ b/Cql/CqlToElmTests/(tests)/StartsEndsTest.cs @@ -8,7 +8,7 @@ public class StartsEndsTest : Base [TestMethod] public void Starts_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library StartsEndsTest version '1.0.0' define private Starts_False: Interval[@2023-01-01, @2023-06-30] starts Interval[@2023-04-01, @2023-04-30] @@ -37,7 +37,7 @@ library StartsEndsTest version '1.0.0' [TestMethod] public void Starts_True() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library StartsEndsTest version '1.0.0' define private Starts_True: Interval[0, 5] starts Interval[0,7] @@ -66,7 +66,7 @@ library StartsEndsTest version '1.0.0' [TestMethod] public void Ends_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library StartsEndsTest version '1.0.0' define private Ends_False: Interval[-1, 7] ends Interval[0,7] diff --git a/Cql/CqlToElmTests/StreamInspectorTest.cs b/Cql/CqlToElmTests/(tests)/StreamInspectorTest.cs similarity index 100% rename from Cql/CqlToElmTests/StreamInspectorTest.cs rename to Cql/CqlToElmTests/(tests)/StreamInspectorTest.cs diff --git a/Cql/CqlToElmTests/StringTest.cs b/Cql/CqlToElmTests/(tests)/StringTest.cs similarity index 75% rename from Cql/CqlToElmTests/StringTest.cs rename to Cql/CqlToElmTests/(tests)/StringTest.cs index 848ce54be..138cd076c 100644 --- a/Cql/CqlToElmTests/StringTest.cs +++ b/Cql/CqlToElmTests/(tests)/StringTest.cs @@ -8,7 +8,7 @@ public class StringTest : Base [TestMethod] public void ReplaceMatchesSpaces() { - var library = CreateCqlApi().MakeLibraryFromExpression("ReplaceMatches('All that glitters is not gold', '\\\\s', '\\$')"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("ReplaceMatches('All that glitters is not gold', '\\\\s', '\\$')"); var replace = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(replace, library); result.Should().Be("All$that$glitters$is$not$gold"); diff --git a/Cql/CqlToElmTests/SubtractionTest.cs b/Cql/CqlToElmTests/(tests)/SubtractionTest.cs similarity index 95% rename from Cql/CqlToElmTests/SubtractionTest.cs rename to Cql/CqlToElmTests/(tests)/SubtractionTest.cs index b91d2d204..6443ca8b8 100644 --- a/Cql/CqlToElmTests/SubtractionTest.cs +++ b/Cql/CqlToElmTests/(tests)/SubtractionTest.cs @@ -14,7 +14,7 @@ public class SubtractionTest : Base [TestMethod] public void Subtract_Integer_from_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Integer_from_Integer version '1.0.0' define private Subtract: 2 - 1 @@ -59,7 +59,7 @@ library Subtract_Integer_from_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(int?)); @@ -73,7 +73,7 @@ library Subtract_Integer_from_Integer version '1.0.0' [TestMethod] public void Subtract_Long_from_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Long_from_Long version '1.0.0' define private Subtract: 1L - 2L @@ -118,7 +118,7 @@ library Subtract_Long_from_Long version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -129,7 +129,7 @@ library Subtract_Long_from_Long version '1.0.0' [TestMethod] public void Subtract_Decimal_from_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Decimal_from_Decimal version '1.0.0' define private Subtract: 2.0 - 1.0 @@ -175,7 +175,7 @@ library Subtract_Decimal_from_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -186,7 +186,7 @@ library Subtract_Decimal_from_Decimal version '1.0.0' [TestMethod] public void Subtract_Quantity_from_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Decimal_from_Quantity version '1.0.0' define private Subtract: -1.0 '1' - 2.0 '1' @@ -231,7 +231,7 @@ library Subtract_Decimal_from_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -249,7 +249,7 @@ library Subtract_Decimal_from_Quantity version '1.0.0' [TestMethod] public void Subtract_Integer_from_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Integer_from_Long version '1.0.0' define private Subtract: 2 - 1L @@ -294,7 +294,7 @@ library Subtract_Integer_from_Long version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -308,7 +308,7 @@ library Subtract_Integer_from_Long version '1.0.0' [TestMethod] public void Subtract_Integer_from_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Integer_from_Decimal version '1.0.0' define private Subtract: 2 - 1.0 @@ -353,7 +353,7 @@ library Subtract_Integer_from_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -367,7 +367,7 @@ library Subtract_Integer_from_Decimal version '1.0.0' [TestMethod] public void Subtract_Integer_from_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Integer_from_Quantity version '1.0.0' define private Subtract: 2 - 1.0 '1' @@ -412,7 +412,7 @@ library Subtract_Integer_from_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -426,7 +426,7 @@ library Subtract_Integer_from_Quantity version '1.0.0' [TestMethod] public void Subtract_Long_from_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Long_from_Decimal version '1.0.0' define private Subtract: 1L - 2.0 @@ -471,7 +471,7 @@ library Subtract_Long_from_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -485,7 +485,7 @@ library Subtract_Long_from_Decimal version '1.0.0' [TestMethod] public void Subtract_Long_from_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Integer_from_Quantity version '1.0.0' define private Subtract: 1L - 2.0 '1' @@ -530,7 +530,7 @@ library Subtract_Integer_from_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -544,7 +544,7 @@ library Subtract_Integer_from_Quantity version '1.0.0' [TestMethod] public void Subtract_Decimal_from_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Decimal_from_Quantity version '1.0.0' define private Subtract: -1.0 - 2.0 '1' @@ -591,7 +591,7 @@ library Subtract_Decimal_from_Quantity version '1.0.0' Assert.AreEqual(UCUMUnits.Default, rhs.unit); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -612,7 +612,7 @@ library Subtract_Decimal_from_Quantity version '1.0.0' [TestMethod] public void Subtract_Long_from_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Long_from_Integer version '1.0.0' define private Subtract: 1L - 2 @@ -657,7 +657,7 @@ library Subtract_Long_from_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -668,7 +668,7 @@ library Subtract_Long_from_Integer version '1.0.0' [TestMethod] public void Subtract_Decimal_from_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Decimal_from_Integer version '1.0.0' define private Subtract: 5.25 - 2 @@ -713,7 +713,7 @@ library Subtract_Decimal_from_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -724,7 +724,7 @@ library Subtract_Decimal_from_Integer version '1.0.0' [TestMethod] public void Subtract_Quantity_from_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Decimal_from_Integer version '1.0.0' define private Subtract: 5.25 '1' - 2 @@ -769,7 +769,7 @@ library Subtract_Decimal_from_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -783,7 +783,7 @@ library Subtract_Decimal_from_Integer version '1.0.0' [TestMethod] public void Subtract_Decimal_from_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Decimal_from_Long version '1.0.0' define private Subtract: 5.25 - 2L @@ -828,7 +828,7 @@ library Subtract_Decimal_from_Long version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -839,7 +839,7 @@ library Subtract_Decimal_from_Long version '1.0.0' [TestMethod] public void Subtract_Quantity_from_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Quantity_from_Long version '1.0.0' define private Subtract: 5.25 '1' - 2L @@ -884,7 +884,7 @@ library Subtract_Quantity_from_Long version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -898,7 +898,7 @@ library Subtract_Quantity_from_Long version '1.0.0' [TestMethod] public void Subtract_Quantity_from_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Quantity_from_Decimal version '1.0.0' define private Subtract: 5.25 '1' - 2.0 @@ -943,7 +943,7 @@ library Subtract_Quantity_from_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -959,7 +959,7 @@ library Subtract_Quantity_from_Decimal version '1.0.0' [TestMethod] public void Subtract_Three_Decimals() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Decimal_from_Decimal version '1.0.0' define private Subtract: 6.0 - (2.0 - 3.0) @@ -1004,7 +1004,7 @@ library Subtract_Decimal_from_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -1015,7 +1015,7 @@ library Subtract_Decimal_from_Decimal version '1.0.0' [TestMethod] public void Subtract_Quantity_from_Two_Decimals() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library Subtract_Decimal_from_Decimal version '1.0.0' define private Subtract: 6.0 '1' - (2.0 - 3.0) @@ -1060,7 +1060,7 @@ library Subtract_Decimal_from_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(add); + var lambda = ToFluentElmToolkit().Lambda(add); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); diff --git a/Cql/CqlToElmTests/SuccessorTest.cs b/Cql/CqlToElmTests/(tests)/SuccessorTest.cs similarity index 91% rename from Cql/CqlToElmTests/SuccessorTest.cs rename to Cql/CqlToElmTests/(tests)/SuccessorTest.cs index cb64e04eb..4fca7d2b2 100644 --- a/Cql/CqlToElmTests/SuccessorTest.cs +++ b/Cql/CqlToElmTests/(tests)/SuccessorTest.cs @@ -10,7 +10,7 @@ public class SuccessorTest : Base [TestMethod] public void Successor_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library PointFromTest version '1.0.0' define private Point_From_Integers: successor of 2 @@ -30,7 +30,7 @@ library PointFromTest version '1.0.0' Assert.IsInstanceOfType(successor.operand, typeof(Literal)); - var lambda = CreateElmApi().Lambda(successor); + var lambda = ToFluentElmToolkit().Lambda(successor); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); @@ -43,7 +43,7 @@ library PointFromTest version '1.0.0' [TestMethod] public void Successor_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library PointFromTest version '1.0.0' define private Point_From_Integers: successor of (null as Integer) @@ -63,7 +63,7 @@ library PointFromTest version '1.0.0' Assert.IsInstanceOfType(successor.operand, typeof(As)); - var lambda = CreateElmApi().Lambda(successor); + var lambda = ToFluentElmToolkit().Lambda(successor); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); diff --git a/Cql/CqlToElmTests/SymbolTableTest.cs b/Cql/CqlToElmTests/(tests)/SymbolTableTest.cs similarity index 98% rename from Cql/CqlToElmTests/SymbolTableTest.cs rename to Cql/CqlToElmTests/(tests)/SymbolTableTest.cs index 87547a847..9ba007db0 100644 --- a/Cql/CqlToElmTests/SymbolTableTest.cs +++ b/Cql/CqlToElmTests/(tests)/SymbolTableTest.cs @@ -1,7 +1,6 @@ using Hl7.Cql.CqlToElm.Builtin; using Hl7.Cql.CqlToElm.Scopes; using Hl7.Cql.Elm; -using CqlSdkPrototype.Cql.Internal; namespace Hl7.Cql.CqlToElm.Test { @@ -11,7 +10,7 @@ namespace Hl7.Cql.CqlToElm.Test public class SymbolTableTest : Base { private static VersionedIdentifier TestId => new VersionedIdentifier { id = "Test", version = "1.0.0" }; - private static SystemLibrary SystemLibrary => CreateCqlApi().AsInternal().Services.ServiceProvider.GetSystemLibrary(); + private static SystemLibrary SystemLibrary => CreateFluentCqlToolkit().GetSystemLibrary(); [TestMethod] public void Add_Local_Expression() diff --git a/Cql/CqlToElmTests/TagsTest.cs b/Cql/CqlToElmTests/(tests)/TagsTest.cs similarity index 77% rename from Cql/CqlToElmTests/TagsTest.cs rename to Cql/CqlToElmTests/(tests)/TagsTest.cs index ca92cb72e..8e41f28e0 100644 --- a/Cql/CqlToElmTests/TagsTest.cs +++ b/Cql/CqlToElmTests/(tests)/TagsTest.cs @@ -1,7 +1,8 @@ -using CqlSdkPrototype.Cql.Extensions; -using CqlSdkPrototype.Elm.Extensibility; +using CqlSdkPrototype.Cql.Fluent; +using CqlSdkPrototype.Cql.Fluent.Extensions; +using CqlSdkPrototype.Elm.Fluent.Extensions; using CqlSdkPrototype.Infrastructure; -using CqlSdkPrototype.Runtime.Extensions; +using CqlSdkPrototype.Invocation.Fluent.Extensions; namespace Hl7.Cql.CqlToElm.Test; @@ -43,14 +44,15 @@ context Patient [Condition: "Injury due to falling rock"] C where (C.onset.value as DateTime) during "Measurement Period" """); - var cql = CreateCqlApi().AddCqlLibraryString(cqlLibraryString).Translate(); - var elm = cql.CreateElmApi().Compile(); + var elmToolkit = CreateFluentCqlToolkit() + .AddCqlLibraryString(cqlLibraryString) + .CompileCqlToAssemblies(); - _ = elm.AsExtendable().Entries.First().Value.CSharpSourceCode; // Debug this line to see the C# code generated by the CQL-to-ELM compiler + _ = elmToolkit.ElmToAssemblyCompilations.First().Value.CSharpSourceCode; // Debug this line to see the C# code generated by the CQL-to-ELM compiler - using var runtime = elm.CreateRuntimeScope(); - _ = runtime.Libraries[cqlLibraryString.VersionedLibraryIdentifier] + using var librarySetInvoker = elmToolkit.ToLibrarySetInvoker(); + _ = librarySetInvoker.LibraryInvokers[cqlLibraryString.VersionedLibraryIdentifier] .Definitions["Injury due to falling rock within measurement period"] .TagValuesByName; diff --git a/Cql/CqlToElmTests/TimingExpressionTest.cs b/Cql/CqlToElmTests/(tests)/TimingExpressionTest.cs similarity index 93% rename from Cql/CqlToElmTests/TimingExpressionTest.cs rename to Cql/CqlToElmTests/(tests)/TimingExpressionTest.cs index 7df691ea8..44efcff76 100644 --- a/Cql/CqlToElmTests/TimingExpressionTest.cs +++ b/Cql/CqlToElmTests/(tests)/TimingExpressionTest.cs @@ -9,7 +9,7 @@ public class TimingExpressionTest : Base public void OnOrAfterMonthOf() { // https://cql.hl7.org/09-b-cqlreference.html#same-or-after-2 - var library = CreateCqlApi().MakeLibraryFromExpression("Interval[@2012-12-01, @2013-12-01] on or after month of @2012-11-15"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("Interval[@2012-12-01, @2013-12-01] on or after month of @2012-11-15"); var sameOrAfter = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); sameOrAfter.Should().HaveType(SystemTypes.BooleanType); sameOrAfter.operand.Should().NotBeNull(); @@ -23,7 +23,7 @@ public void OnOrAfterMonthOf() [TestMethod] public void Starts1DayOrLessOnOrAfter() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library IntervalTest version '1.0.0' define private Issue32: Interval[@2017-12-20T10:30:00, @2017-12-20T12:00:00] starts 1 day or less on or after day of start of Interval[@2017-12-20T11:00:00, @2017-12-21T21:00:00] @@ -136,7 +136,7 @@ library IntervalTest version '1.0.0' [TestMethod] public void Overlaps() { - var library = CreateCqlApi( + var library = CreateFluentCqlToolkit( EnableListPromotion: true, EnableListDemotion: true, EnableIntervalPromotion: true, @@ -155,7 +155,7 @@ public void Overlaps() [TestMethod] public void TestOnOrAfterDateTrue() { - var library = CreateCqlApi().MakeLibraryFromExpression("Interval[@2012-12-01, @2013-12-01] on or after month of @2012-11-15"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("Interval[@2012-12-01, @2013-12-01] on or after month of @2012-11-15"); var sameOrAfter = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(sameOrAfter, library); result.Should().BeTrue(); @@ -164,7 +164,7 @@ public void TestOnOrAfterDateTrue() [TestMethod] public void TestOnOrBeforeDateTrue() { - var library = CreateCqlApi().MakeLibraryFromExpression("Interval[@2012-10-01, @2012-11-01] on or before month of @2012-11-15"); + var library = CreateFluentCqlToolkit().MakeLibraryFromExpression("Interval[@2012-10-01, @2012-11-01] on or before month of @2012-11-15"); var sameOrBefore = library.Should().BeACorrectlyInitializedLibraryWithStatementOfType(); var result = Run(sameOrBefore, library); result.Should().BeTrue(); diff --git a/Cql/CqlToElmTests/TruncatedDivisionTest.cs b/Cql/CqlToElmTests/(tests)/TruncatedDivisionTest.cs similarity index 95% rename from Cql/CqlToElmTests/TruncatedDivisionTest.cs rename to Cql/CqlToElmTests/(tests)/TruncatedDivisionTest.cs index ee806e131..d6f3f5eac 100644 --- a/Cql/CqlToElmTests/TruncatedDivisionTest.cs +++ b/Cql/CqlToElmTests/(tests)/TruncatedDivisionTest.cs @@ -13,7 +13,7 @@ public class TruncatedDivisionTest : Base [TestMethod] public void TruncatedDivide_Integer_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Integer_by_Integer version '1.0.0' define private TruncatedDivide_Integer_by_Integer: 2 div 4 @@ -58,7 +58,7 @@ library TruncatedDivide_Integer_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(int?)); @@ -69,7 +69,7 @@ library TruncatedDivide_Integer_by_Integer version '1.0.0' [TestMethod] public void TruncatedDivide_Integer_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Integer_by_Long version '1.0.0' define private TruncatedDivide_Integer_by_Long: 2 div 3L @@ -114,7 +114,7 @@ library TruncatedDivide_Integer_by_Long version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -125,7 +125,7 @@ library TruncatedDivide_Integer_by_Long version '1.0.0' [TestMethod] public void TruncatedDivide_Integer_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Integer_by_Decimal version '1.0.0' define private TruncatedDivide_Integer_by_Decimal: 2 div 3.0 @@ -170,7 +170,7 @@ library TruncatedDivide_Integer_by_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -181,7 +181,7 @@ library TruncatedDivide_Integer_by_Decimal version '1.0.0' [TestMethod] public void TruncatedDivide_Integer_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Integer_by_Quantity version '1.0.0' define private TruncatedDivide_Integer_by_Quantity: 10 div 2.0 '1' @@ -226,7 +226,7 @@ library TruncatedDivide_Integer_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -241,7 +241,7 @@ library TruncatedDivide_Integer_by_Quantity version '1.0.0' [TestMethod] public void TruncatedDivide_Integer_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Integer_by_Null version '1.0.0' define private TruncatedDivide_Integer_by_Null: 1 div null @@ -285,7 +285,7 @@ library TruncatedDivide_Integer_by_Null version '1.0.0' Assert.IsNotNull(lhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Integer", lhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -295,7 +295,7 @@ library TruncatedDivide_Integer_by_Null version '1.0.0' [TestMethod] public void TruncatedDivide_Null_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Null_by_Integer version '1.0.0' define private TruncatedDivide_Null_by_Integer: null div 1 @@ -339,7 +339,7 @@ library TruncatedDivide_Null_by_Integer version '1.0.0' Assert.IsNotNull(rhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Integer", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -353,7 +353,7 @@ library TruncatedDivide_Null_by_Integer version '1.0.0' [TestMethod] public void TruncatedDivide_Long_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Long_by_Integer version '1.0.0' define private TruncatedDivide_Long_by_Integer: 10L div 2 @@ -398,7 +398,7 @@ library TruncatedDivide_Long_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -409,7 +409,7 @@ library TruncatedDivide_Long_by_Integer version '1.0.0' [TestMethod] public void TruncatedDivide_Long_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Long_by_Long version '1.0.0' define private TruncatedDivide_Long_by_Long: 100L div 10L @@ -454,7 +454,7 @@ library TruncatedDivide_Long_by_Long version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(long?)); @@ -465,7 +465,7 @@ library TruncatedDivide_Long_by_Long version '1.0.0' [TestMethod] public void TruncatedDivide_Long_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Long_by_Decimal version '1.0.0' define private TruncatedDivide_Long_by_Decimal: -3L div 2.0 @@ -510,7 +510,7 @@ library TruncatedDivide_Long_by_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -521,7 +521,7 @@ library TruncatedDivide_Long_by_Decimal version '1.0.0' [TestMethod] public void TruncatedDivide_Long_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Long_by_Quantity version '1.0.0' define private TruncatedDivide_Long_by_Quantity: 20L div 5.0 '1' @@ -566,7 +566,7 @@ library TruncatedDivide_Long_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -580,7 +580,7 @@ library TruncatedDivide_Long_by_Quantity version '1.0.0' [TestMethod] public void TruncatedDivide_Long_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Long_by_Null version '1.0.0' define private TruncatedDivide_Long_by_Null: 1L div null @@ -624,7 +624,7 @@ library TruncatedDivide_Long_by_Null version '1.0.0' Assert.IsNotNull(lhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Long", lhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -634,7 +634,7 @@ library TruncatedDivide_Long_by_Null version '1.0.0' [TestMethod] public void TruncatedDivide_Null_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Null_by_Long version '1.0.0' define private TruncatedDivide_Null_by_Long: null div 1L @@ -678,7 +678,7 @@ library TruncatedDivide_Null_by_Long version '1.0.0' Assert.IsNotNull(rhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Long", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -692,7 +692,7 @@ library TruncatedDivide_Null_by_Long version '1.0.0' [TestMethod] public void TruncatedDivide_Decimal_by_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Decimal_by_Integer version '1.0.0' define private TruncatedDivide_Decimal_by_Integer: 0.0 div 3 @@ -737,7 +737,7 @@ library TruncatedDivide_Decimal_by_Integer version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -748,7 +748,7 @@ library TruncatedDivide_Decimal_by_Integer version '1.0.0' [TestMethod] public void TruncatedDivide_Decimal_by_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library DefaultConverter version '1.0.0' define private DefaultConverter: 5.0 div 5L @@ -793,7 +793,7 @@ library DefaultConverter version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -804,7 +804,7 @@ library DefaultConverter version '1.0.0' [TestMethod] public void TruncatedDivide_Decimal_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Decimal_by_Decimal version '1.0.0' define private TruncatedDivide_Decimal_by_Decimal: -10.0 div 10.0 @@ -849,7 +849,7 @@ library TruncatedDivide_Decimal_by_Decimal version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(decimal?)); @@ -860,7 +860,7 @@ library TruncatedDivide_Decimal_by_Decimal version '1.0.0' [TestMethod] public void TruncatedDivide_Decimal_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Decimal_by_Quantity version '1.0.0' define private TruncatedDivide_Decimal_by_Quantity: 3.0 div 2.0 '1' @@ -905,7 +905,7 @@ library TruncatedDivide_Decimal_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -919,7 +919,7 @@ library TruncatedDivide_Decimal_by_Quantity version '1.0.0' [TestMethod] public void TruncatedDivide_Decimal_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Decimal_by_Null version '1.0.0' define private TruncatedDivide_Decimal_by_Null: 1.0 div null @@ -963,7 +963,7 @@ library TruncatedDivide_Decimal_by_Null version '1.0.0' Assert.IsNotNull(lhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", lhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -973,7 +973,7 @@ library TruncatedDivide_Decimal_by_Null version '1.0.0' [TestMethod] public void TruncatedDivide_Null_by_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Null_by_Decimal version '1.0.0' define private TruncatedDivide_Null_by_Decimal: null div 1.0 @@ -1017,7 +1017,7 @@ library TruncatedDivide_Null_by_Decimal version '1.0.0' Assert.IsNotNull(rhsnts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.AreEqual(null, result); @@ -1031,7 +1031,7 @@ library TruncatedDivide_Null_by_Decimal version '1.0.0' [TestMethod] public void TruncatedDivide_Quantity_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Quantity_by_Quantity version '1.0.0' define private TruncatedDivide_Quantity_by_Quantity: 3.0 '1' div 2.0 '1' @@ -1076,7 +1076,7 @@ library TruncatedDivide_Quantity_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -1090,7 +1090,7 @@ library TruncatedDivide_Quantity_by_Quantity version '1.0.0' [TestMethod] public void TruncatedDivide_Quantity_by_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Quantity_by_Null version '1.0.0' define private TruncatedDivide_Quantity_by_Null: 3.0 '1' div null @@ -1135,7 +1135,7 @@ library TruncatedDivide_Quantity_by_Null version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -1145,7 +1145,7 @@ library TruncatedDivide_Quantity_by_Null version '1.0.0' [TestMethod] public void TruncatedDivide_Null_by_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TruncatedDivide_Null_by_Quantity version '1.0.0' define private TruncatedDivide_Null_by_Quantity: null div 3.0 '1' @@ -1190,7 +1190,7 @@ library TruncatedDivide_Null_by_Quantity version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Quantity", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(divide); + var lambda = ToFluentElmToolkit().Lambda(divide); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); diff --git a/Cql/CqlToElmTests/TypeExtentTest.cs b/Cql/CqlToElmTests/(tests)/TypeExtentTest.cs similarity index 92% rename from Cql/CqlToElmTests/TypeExtentTest.cs rename to Cql/CqlToElmTests/(tests)/TypeExtentTest.cs index 7dabd563a..071ea26c4 100644 --- a/Cql/CqlToElmTests/TypeExtentTest.cs +++ b/Cql/CqlToElmTests/(tests)/TypeExtentTest.cs @@ -11,7 +11,7 @@ public class TypeExtentTest : Base [TestMethod] public void TypeExtent_Minimum_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TypeExtentTest version '1.0.0' define private TypeExtent_Minimum_Integer: minimum Integer @@ -32,7 +32,7 @@ library TypeExtentTest version '1.0.0' Assert.IsNotNull(nts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Integer", nts.name.Name); - var lambda = CreateElmApi().Lambda(extent); + var lambda = ToFluentElmToolkit().Lambda(extent); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -45,7 +45,7 @@ library TypeExtentTest version '1.0.0' [TestMethod] public void TypeExtent_Maximum_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TypeExtentTest version '1.0.0' define private TypeExtent_Maximum_Integer: maximum Integer @@ -66,7 +66,7 @@ library TypeExtentTest version '1.0.0' Assert.IsNotNull(nts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Integer", nts.name.Name); - var lambda = CreateElmApi().Lambda(extent); + var lambda = ToFluentElmToolkit().Lambda(extent); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -79,7 +79,7 @@ library TypeExtentTest version '1.0.0' [TestMethod] public void TypeExtent_Minimum_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TypeExtentTest version '1.0.0' define private TypeExtent_Minimum_Long: minimum Long @@ -100,7 +100,7 @@ library TypeExtentTest version '1.0.0' Assert.IsNotNull(nts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Long", nts.name.Name); - var lambda = CreateElmApi().Lambda(extent); + var lambda = ToFluentElmToolkit().Lambda(extent); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -113,7 +113,7 @@ library TypeExtentTest version '1.0.0' [TestMethod] public void TypeExtent_Maximum_Long() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TypeExtentTest version '1.0.0' define private TypeExtent_Maximum_Long: maximum Long @@ -134,7 +134,7 @@ library TypeExtentTest version '1.0.0' Assert.IsNotNull(nts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Long", nts.name.Name); - var lambda = CreateElmApi().Lambda(extent); + var lambda = ToFluentElmToolkit().Lambda(extent); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -147,7 +147,7 @@ library TypeExtentTest version '1.0.0' [TestMethod] public void TypeExtent_Minimum_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TypeExtentTest version '1.0.0' define private TypeExtent_Minimum_Decimal: minimum Decimal @@ -168,7 +168,7 @@ library TypeExtentTest version '1.0.0' Assert.IsNotNull(nts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", nts.name.Name); - var lambda = CreateElmApi().Lambda(extent); + var lambda = ToFluentElmToolkit().Lambda(extent); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -181,7 +181,7 @@ library TypeExtentTest version '1.0.0' [TestMethod] public void TypeExtent_Maximum_Decimal() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TypeExtentTest version '1.0.0' define private TypeExtent_Maximum_Decimal: maximum Decimal @@ -202,7 +202,7 @@ library TypeExtentTest version '1.0.0' Assert.IsNotNull(nts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Decimal", nts.name.Name); - var lambda = CreateElmApi().Lambda(extent); + var lambda = ToFluentElmToolkit().Lambda(extent); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -214,7 +214,7 @@ library TypeExtentTest version '1.0.0' [TestMethod] public void TypeExtent_Minimum_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TypeExtentTest version '1.0.0' define private TypeExtent_Minimum_Quantity: minimum Quantity @@ -235,7 +235,7 @@ library TypeExtentTest version '1.0.0' Assert.IsNotNull(nts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Quantity", nts.name.Name); - var lambda = CreateElmApi().Lambda(extent); + var lambda = ToFluentElmToolkit().Lambda(extent); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -250,7 +250,7 @@ library TypeExtentTest version '1.0.0' [TestMethod] public void TypeExtent_Maximum_Quantity() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TypeExtentTest version '1.0.0' define private TypeExtent_Maximum_Quantity: maximum Quantity @@ -271,7 +271,7 @@ library TypeExtentTest version '1.0.0' Assert.IsNotNull(nts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Quantity", nts.name.Name); - var lambda = CreateElmApi().Lambda(extent); + var lambda = ToFluentElmToolkit().Lambda(extent); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -286,7 +286,7 @@ library TypeExtentTest version '1.0.0' [TestMethod] public void TypeExtent_Minimum_Date() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TypeExtentTest version '1.0.0' define private TypeExtent_Minimum_Date: minimum Date @@ -307,7 +307,7 @@ library TypeExtentTest version '1.0.0' Assert.IsNotNull(nts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Date", nts.name.Name); - var lambda = CreateElmApi().Lambda(extent); + var lambda = ToFluentElmToolkit().Lambda(extent); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -319,7 +319,7 @@ library TypeExtentTest version '1.0.0' [TestMethod] public void TypeExtent_Maximum_Date() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TypeExtentTest version '1.0.0' define private TypeExtent_Maximum_Date: maximum Date @@ -340,7 +340,7 @@ library TypeExtentTest version '1.0.0' Assert.IsNotNull(nts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Date", nts.name.Name); - var lambda = CreateElmApi().Lambda(extent); + var lambda = ToFluentElmToolkit().Lambda(extent); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -352,7 +352,7 @@ library TypeExtentTest version '1.0.0' [TestMethod] public void TypeExtent_Minimum_DateTime() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TypeExtentTest version '1.0.0' define private TypeExtent_Minimum_DateTime: minimum DateTime @@ -373,7 +373,7 @@ library TypeExtentTest version '1.0.0' Assert.IsNotNull(nts.name.Name); Assert.AreEqual($"{{{SystemUri}}}DateTime", nts.name.Name); - var lambda = CreateElmApi().Lambda(extent); + var lambda = ToFluentElmToolkit().Lambda(extent); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -385,7 +385,7 @@ library TypeExtentTest version '1.0.0' [TestMethod] public void TypeExtent_Maximum_DateTime() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TypeExtentTest version '1.0.0' define private TypeExtent_Maximum_DateTime: maximum DateTime @@ -406,7 +406,7 @@ library TypeExtentTest version '1.0.0' Assert.IsNotNull(nts.name.Name); Assert.AreEqual($"{{{SystemUri}}}DateTime", nts.name.Name); - var lambda = CreateElmApi().Lambda(extent); + var lambda = ToFluentElmToolkit().Lambda(extent); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -418,7 +418,7 @@ library TypeExtentTest version '1.0.0' [TestMethod] public void TypeExtent_Minimum_Time() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TypeExtentTest version '1.0.0' define private TypeExtent_Minimum_Time: minimum Time @@ -439,7 +439,7 @@ library TypeExtentTest version '1.0.0' Assert.IsNotNull(nts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Time", nts.name.Name); - var lambda = CreateElmApi().Lambda(extent); + var lambda = ToFluentElmToolkit().Lambda(extent); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); @@ -451,7 +451,7 @@ library TypeExtentTest version '1.0.0' [TestMethod] public void TypeExtent_Maximum_Time() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library TypeExtentTest version '1.0.0' define private TypeExtent_Maximum_Time: maximum Time @@ -472,7 +472,7 @@ library TypeExtentTest version '1.0.0' Assert.IsNotNull(nts.name.Name); Assert.AreEqual($"{{{SystemUri}}}Time", nts.name.Name); - var lambda = CreateElmApi().Lambda(extent); + var lambda = ToFluentElmToolkit().Lambda(extent); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNotNull(result); diff --git a/Cql/CqlToElmTests/VersionTest.cs b/Cql/CqlToElmTests/(tests)/VersionTest.cs similarity index 100% rename from Cql/CqlToElmTests/VersionTest.cs rename to Cql/CqlToElmTests/(tests)/VersionTest.cs diff --git a/Cql/CqlToElmTests/WidthTest.cs b/Cql/CqlToElmTests/(tests)/WidthTest.cs similarity index 92% rename from Cql/CqlToElmTests/WidthTest.cs rename to Cql/CqlToElmTests/(tests)/WidthTest.cs index 5b592e0f0..b3d542269 100644 --- a/Cql/CqlToElmTests/WidthTest.cs +++ b/Cql/CqlToElmTests/(tests)/WidthTest.cs @@ -9,7 +9,7 @@ public class WidthTest : Base [TestMethod] public void Width_Integer() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library WidthTest version '1.0.0' define private Width_Integers: width of Interval[3,7] @@ -30,7 +30,7 @@ library WidthTest version '1.0.0' var interval = (Interval)width.operand; AssertIntervalType(interval.resultTypeSpecifier, $"{{{SystemUri}}}Integer"); - var lambda = CreateElmApi().Lambda(width); + var lambda = ToFluentElmToolkit().Lambda(width); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); @@ -44,7 +44,7 @@ library WidthTest version '1.0.0' [TestMethod] public void Width_Integers_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library WidthTest version '1.0.0' define private Width_Integers_Null: width of (null as Interval) @@ -66,7 +66,7 @@ library WidthTest version '1.0.0' Assert.IsInstanceOfType(@as.operand, typeof(Null)); AssertIntervalType(@as.resultTypeSpecifier, $"{{{SystemUri}}}Integer"); - var lambda = CreateElmApi().Lambda(width); + var lambda = ToFluentElmToolkit().Lambda(width); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); @@ -77,7 +77,7 @@ library WidthTest version '1.0.0' [TestMethod] public void Width_Integers_Null_Interval() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library WidthTest version '1.0.0' define private Width_Integers_Error: width of Interval[1,null) @@ -98,7 +98,7 @@ library WidthTest version '1.0.0' var list = (Interval)width.operand; AssertIntervalType(list.resultTypeSpecifier, $"{{{SystemUri}}}Integer"); - var lambda = CreateElmApi().Lambda(width); + var lambda = ToFluentElmToolkit().Lambda(width); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); diff --git a/Cql/CqlToElmTests/XmlTest.cs b/Cql/CqlToElmTests/(tests)/XmlTest.cs similarity index 85% rename from Cql/CqlToElmTests/XmlTest.cs rename to Cql/CqlToElmTests/(tests)/XmlTest.cs index ae260606a..1f102a0bc 100644 --- a/Cql/CqlToElmTests/XmlTest.cs +++ b/Cql/CqlToElmTests/(tests)/XmlTest.cs @@ -2,7 +2,6 @@ using Hl7.Cql.Elm; using Hl7.Cql.Fhir; using Hl7.Cql.Runtime; -using CqlSdkPrototype.Cql.Internal; namespace Hl7.Cql.CqlToElm.Test { @@ -29,8 +28,8 @@ public void Run(TestCase testCase) // if (testCase.TestName != "AgeInYearsAt") // Assert.Inconclusive("Skipped!"); - var cqlApi = CreateCqlApi(AllowNullIntervals:true); - var expression = cqlApi.Expression(testCase.Expression); + var cqlToolkit = CreateFluentCqlToolkit(AllowNullIntervals:true); + var expression = cqlToolkit.Expression(testCase.Expression); var expressionErrors = expression.GetErrors(); if (expressionErrors.Any()) { @@ -44,7 +43,7 @@ public void Run(TestCase testCase) return; } - var expectation = cqlApi.Expression(testCase.Expectation); + var expectation = cqlToolkit.Expression(testCase.Expectation); var expectationErrors = expectation.GetErrors(); if (expectationErrors.Any()) { @@ -59,25 +58,24 @@ public void Run(TestCase testCase) } Expression equal = Equals(expression, expectation); - var equalLambda = CreateElmApi().Lambda(equal); + var equalLambda = ToFluentElmToolkit().Lambda(equal); var equalDelegate = equalLambda.Compile(); // TODO: These needs to be changed to run through the AssemblyCompiler too var equalResult = (bool?)equalDelegate.DynamicInvoke(CqlContext); if (equalResult != true) { - var expressionValue = CreateElmApi().Lambda(expression).Compile().DynamicInvoke(CqlContext); - var expectationValue = CreateElmApi().Lambda(expectation).Compile().DynamicInvoke(CqlContext); + var expressionValue = ToFluentElmToolkit().Lambda(expression).Compile().DynamicInvoke(CqlContext); + var expectationValue = ToFluentElmToolkit().Lambda(expectation).Compile().DynamicInvoke(CqlContext); Assert.Fail($"Case {testFullName} assertion failed. Expected '{expectationValue}', but got '{expressionValue}'."); } } private static Expression Equals(Expression expression, Expression expectation) { - var cqlApi = CreateCqlApi(); - var serviceProvider = cqlApi.AsInternal().Services.ServiceProvider; - var invocationBuilder = serviceProvider.GetService(); - var elmFactory = serviceProvider.GetService(); + var fluentCqlToolkit = CreateFluentCqlToolkit(); + var invocationBuilder = fluentCqlToolkit.GetInvocationBuilder(); + var elmFactory = fluentCqlToolkit.GetElmFactory(); var equal = invocationBuilder.Invoke(SystemLibrary.Equal, expression, expectation); var @if = new If { diff --git a/Cql/CqlToElmTests/XorTest.cs b/Cql/CqlToElmTests/(tests)/XorTest.cs similarity index 95% rename from Cql/CqlToElmTests/XorTest.cs rename to Cql/CqlToElmTests/(tests)/XorTest.cs index 589da4940..1684e3e56 100644 --- a/Cql/CqlToElmTests/XorTest.cs +++ b/Cql/CqlToElmTests/(tests)/XorTest.cs @@ -9,7 +9,7 @@ public class XorTest : Base [TestMethod] public void True_Xor_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library XorTest version '1.0.0' define private True_Xor_False: true xor false @@ -54,7 +54,7 @@ library XorTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(xor); + var lambda = ToFluentElmToolkit().Lambda(xor); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -65,7 +65,7 @@ library XorTest version '1.0.0' [TestMethod] public void True_Xor_True() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library XorTest version '1.0.0' define private True_Xor_True: true xor true @@ -110,7 +110,7 @@ library XorTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(xor); + var lambda = ToFluentElmToolkit().Lambda(xor); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -121,7 +121,7 @@ library XorTest version '1.0.0' [TestMethod] public void False_Xor_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library XorTest version '1.0.0' define private False_Xor_False: false xor false @@ -166,7 +166,7 @@ library XorTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(xor); + var lambda = ToFluentElmToolkit().Lambda(xor); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsInstanceOfType(result, typeof(bool?)); @@ -177,7 +177,7 @@ library XorTest version '1.0.0' [TestMethod] public void True_Xor_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library XorTest version '1.0.0' define private True_Xor_Null: true xor null @@ -222,7 +222,7 @@ library XorTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(xor); + var lambda = ToFluentElmToolkit().Lambda(xor); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -232,7 +232,7 @@ library XorTest version '1.0.0' [TestMethod] public void Null_Xor_False() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library XorTest version '1.0.0' define private Null_Xor_False: null xor false @@ -277,7 +277,7 @@ library XorTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(xor); + var lambda = ToFluentElmToolkit().Lambda(xor); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -288,7 +288,7 @@ library XorTest version '1.0.0' [TestMethod] public void Null_Xor_Null() { - var library = CreateCqlApi().MakeLibrary(""" + var library = CreateFluentCqlToolkit().MakeLibrary(""" library XorTest version '1.0.0' define private Null_Xor_Null: null xor null @@ -333,7 +333,7 @@ library XorTest version '1.0.0' Assert.AreEqual($"{{{SystemUri}}}Boolean", rhsnts.name.Name); } - var lambda = CreateElmApi().Lambda(xor); + var lambda = ToFluentElmToolkit().Lambda(xor); var dg = lambda.Compile(); var result = dg.DynamicInvoke(FhirCqlContext.ForBundle()); Assert.IsNull(result); @@ -343,7 +343,7 @@ library XorTest version '1.0.0' [TestMethod] public void True_Xor_1() { - CreateCqlApi().MakeLibrary(""" + CreateFluentCqlToolkit().MakeLibrary(""" library XorTest version '1.0.0' define private True_Xor_1: true xor 1 diff --git a/Cql/CqlToElmTests/Base.cs b/Cql/CqlToElmTests/Base.cs index 14280421c..5a985e463 100644 --- a/Cql/CqlToElmTests/Base.cs +++ b/Cql/CqlToElmTests/Base.cs @@ -5,12 +5,16 @@ using Hl7.Cql.Runtime; using CqlSdkPrototype.Cql; using CqlSdkPrototype.Elm; -using CqlSdkPrototype.Elm.Internal; -using CqlSdkPrototype.Runtime; -using CqlSdkPrototype.Runtime.Extensions; using CqlSdkPrototype.Infrastructure; +using CqlSdkPrototype.Invocation; using Hl7.Cql.Abstractions.Exceptions; using Hl7.Cql.Model; +using CqlSdkPrototype.Cql.Fluent; +using CqlSdkPrototype.Elm.Fluent; +using CqlSdkPrototype.Elm.Fluent.Extensions; +using CqlSdkPrototype.Invocation.Extensions; +using CqlSdkPrototype.Invocation.Fluent; +using CqlSdkPrototype.Invocation.Fluent.Extensions; namespace Hl7.Cql.CqlToElm.Test { @@ -32,21 +36,21 @@ public class Base CqlContext? ctx = null) { ctx ??= DefaultCqlContext; - var elmApi = CreateElmApi(); - var lambda = elmApi.Lambda(expression); + var elmToolkit = ToFluentElmToolkit(); + var lambda = elmToolkit.Lambda(expression); var expressionName = "TempExpression"; - var state = elmApi.AsInternal().State; + var elmToolkitServices = elmToolkit; LibrarySet librarySet = new("TempLibrarySet", library); DefinitionDictionary definitions = new(); definitions.Add(library.GetVersionedIdentifier()!, expressionName, lambda); - var generateCSharp = state.LibrarySetCSharpCodeGenerator.GenerateCSharp(librarySet, definitions); - var compile = state.AssemblyCompiler.Compile(librarySet, generateCSharp, state.Options.AssemblyCompilerDebugInformationFormat); - var assemblyBytes = compile.Single().assemblyDataWithSourceCode.AssemblyBytes; - - using var scope = new RuntimeApi() - .AddAssemblies([AssemblyData.Default with { AssemblyBytes = assemblyBytes }]) - .CreateRuntimeScope(); - var result = scope.GetLibraryDefinitionResult(ctx!, CqlVersionedLibraryIdentifier.FromVersionedIdentifier(library.identifier), expressionName); + var generateCSharp = elmToolkitServices.GetLibrarySetCSharpCodeGenerator().GenerateCSharp(librarySet, definitions); + var compile = elmToolkitServices.GetAssemblyCompiler().Compile(librarySet, generateCSharp, elmToolkit.ProcessorConfig.AssemblyCompilerDebugInformationFormat); + var assemblyBytes = compile.Single().assemblyBinaryWithSourceCode.AssemblyBytes; + + using var librarySetInvoker = new FluentInvocationToolkit() + .AddAssemblyBinaries(AssemblyBinary.Default with { AssemblyBytes = assemblyBytes }) + .ToLibrarySetInvoker(); + var result = librarySetInvoker.GetLibraryDefinitionResult(ctx!, CqlVersionedLibraryIdentifier.FromVersionedIdentifier(library.identifier), expressionName); return result; } @@ -60,7 +64,7 @@ public class Base protected static void AssertResult(Expression be, T expected) { - var lambda = CreateElmApi().Lambda(@be); + var lambda = ToFluentElmToolkit().Lambda(@be); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); @@ -79,7 +83,7 @@ protected static void AssertResult(Expression be, T expected) protected static void AssertNullResult(Expression be) { - var lambda = CreateElmApi().Lambda(@be); + var lambda = ToFluentElmToolkit().Lambda(@be); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); @@ -162,7 +166,7 @@ protected static void AssertList( Assert.IsNotNull(list.element); Assert.AreEqual(expectedValues.Length, list.element.Length); - var lambda = CreateElmApi().Lambda(list); + var lambda = ToFluentElmToolkit().Lambda(list); var dg = lambda.Compile(); var ctx = FhirCqlContext.ForBundle(); var result = dg.DynamicInvoke(ctx); @@ -174,13 +178,13 @@ protected static void AssertList( Assert.AreEqual(true, ctx.Operators.Comparer.Equals(expectedValues[i], array[i], precision)); } - protected static ILoggerFactory LoggerFactory { get; } = + private static ILoggerFactory LoggerFactory { get; } = new ServiceCollection() .AddLogging(lb => lb.AddConsole()) .BuildServiceProvider() .GetRequiredService(); - protected static CqlApi CreateCqlApi( + protected static FluentCqlToolkit CreateFluentCqlToolkit( ImmutableHashSet? Models = null, ImmutableHashSet? ModelInfos = null, AmbiguousTypeBehavior AmbiguousTypeBehavior = AmbiguousTypeBehavior.Error, @@ -189,9 +193,9 @@ protected static CqlApi CreateCqlApi( bool EnableIntervalPromotion = false, bool EnableIntervalDemotion = false, bool AllowNullIntervals = false) => - new CqlApi( + new( LoggerFactory, - new CqlApiOptions( + new CqlToElmTranslatorConfig( ProcessBatchItemExceptionHandling: ProcessBatchItemExceptionHandling.ThrowException, Models: Models ?? [CqlModel.ElmR1, CqlModel.Fhir401], ModelInfos: ModelInfos, @@ -200,16 +204,16 @@ protected static CqlApi CreateCqlApi( EnableListPromotion: EnableListPromotion, EnableIntervalDemotion: EnableIntervalDemotion, EnableIntervalPromotion: EnableIntervalPromotion, - AllowNullInterval: AllowNullIntervals - )); + AllowNullIntervals: AllowNullIntervals + )); - internal static ElmApi CreateElmApi( + internal static FluentElmToolkit ToFluentElmToolkit( ImmutableHashSet? models = null, ImmutableHashSet? modelInfos = null, AmbiguousTypeBehavior ambiguousTypeBehavior = AmbiguousTypeBehavior.Error, bool enableListPromotion = false) => - CreateCqlApi(models, modelInfos, ambiguousTypeBehavior, enableListPromotion) - .CreateElmApi(_ => new ElmApiOptions( + CreateFluentCqlToolkit(models, modelInfos, ambiguousTypeBehavior, enableListPromotion) + .ToFluentElmToolkit(_ => new ElmToAssemblyCompilerConfig( ProcessBatchItemExceptionHandling.ThrowException, Debugger.IsAttached ? AssemblyCompilerDebugInformationFormat.Embedded : AssemblyCompilerDebugInformationFormat.None)); } diff --git a/Cql/CqlToElmTests/CqlFluentToolkitExtensions.cs b/Cql/CqlToElmTests/CqlFluentToolkitExtensions.cs new file mode 100644 index 000000000..67a323226 --- /dev/null +++ b/Cql/CqlToElmTests/CqlFluentToolkitExtensions.cs @@ -0,0 +1,81 @@ +using CqlSdkPrototype.Cql.Fluent; +using CqlSdkPrototype.Cql.Fluent.Extensions; +using CqlSdkPrototype.Infrastructure; +using Hl7.Cql.CqlToElm.Builtin; +using Hl7.Cql.Elm; +using Expression = Hl7.Cql.Elm.Expression; + +namespace Hl7.Cql.CqlToElm.Test; + +internal static class FluentCqlToolkitExtensions +{ + private static TService GetCqlRequiredService(this FluentCqlToolkit fluentCqlToolkit) where TService : notnull => + fluentCqlToolkit.ServiceProvider.GetRequiredService(); + + public static CqlToElmConverter GetCqlToElmConverter(this FluentCqlToolkit fluentCqlToolkit) => + fluentCqlToolkit.GetCqlRequiredService(); + + public static CoercionProvider GetCoercionProvider(this FluentCqlToolkit fluentCqlToolkit) => + fluentCqlToolkit.GetCqlRequiredService(); + + public static ElmFactory GetElmFactory(this FluentCqlToolkit fluentCqlToolkit) => + fluentCqlToolkit.GetCqlRequiredService(); + + public static MessageProvider GetMessageProvider(this FluentCqlToolkit fluentCqlToolkit) => + fluentCqlToolkit.GetCqlRequiredService(); + + public static InvocationBuilder GetInvocationBuilder(this FluentCqlToolkit fluentCqlToolkit) => + fluentCqlToolkit.GetCqlRequiredService(); + + public static SystemLibrary GetSystemLibrary(this FluentCqlToolkit fluentCqlToolkit) => + fluentCqlToolkit.GetCqlRequiredService(); + + private static CqlLibraryString FHIRHelpers { get; } = CqlLibraryString.Parse(File.ReadAllText(@"Input\FHIRHelpers-4.0.1.cql")); + + public static FluentCqlToolkit AddFHIRHelpers(this FluentCqlToolkit fluentCqlToolkit) => fluentCqlToolkit.AddCqlLibraryString(FHIRHelpers); + + public static Library MakeLibrary( + this FluentCqlToolkit fluentCqlToolkit, + string cql, + params string[] expectedErrors) + { + var cqlLibraryString = CqlLibraryString.Parse(cql); + + var library = fluentCqlToolkit + .AddCqlLibraryString(cqlLibraryString) + .TranslateCqlToElm() + .CqlToElmTranslations[cqlLibraryString.VersionedLibraryIdentifier] + .ElmLibrary!; + + if (expectedErrors.Any()) + library.ShouldReportError(expectedErrors); + else + library.ShouldSucceed(); + + return library; + } + + public static Library MakeLibraryFromExpression( + this FluentCqlToolkit fluentCqlToolkit, + string expression, + string[]? expectedErrors = null, + [System.Runtime.CompilerServices.CallerMemberName] string memberName = "") + { + string cql = $""" + library Test version '1.0.0' + + define private "{memberName}": {expression} + """; + var lib = fluentCqlToolkit.MakeLibrary(cql, expectedErrors ?? []); + return lib; + } + + public static Expression Expression( + this FluentCqlToolkit fluentCqlToolkit, + string expression, + [System.Runtime.CompilerServices.CallerMemberName] + string memberName = "") + { + return fluentCqlToolkit.MakeLibraryFromExpression(expression, memberName: memberName).statements[0].expression; + } +} \ No newline at end of file diff --git a/Cql/CqlToElmTests/CqlToElmTests.csproj.DotSettings b/Cql/CqlToElmTests/CqlToElmTests.csproj.DotSettings new file mode 100644 index 000000000..cd412a548 --- /dev/null +++ b/Cql/CqlToElmTests/CqlToElmTests.csproj.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/Cql/CqlToElmTests/ElmFluentToolkitExtensions.cs b/Cql/CqlToElmTests/ElmFluentToolkitExtensions.cs new file mode 100644 index 000000000..1369b3e34 --- /dev/null +++ b/Cql/CqlToElmTests/ElmFluentToolkitExtensions.cs @@ -0,0 +1,58 @@ +using CqlSdkPrototype.Elm.Fluent; +using Hl7.Cql.CodeGeneration.NET; +using Hl7.Cql.Compiler; +using Hl7.Cql.Elm; +using Hl7.Cql.Runtime; + +namespace Hl7.Cql.CqlToElm.Test; + +using Expression = Hl7.Cql.Elm.Expression; + +internal static class FluentElmToolkitExtensions +{ + public static LibrarySetCSharpCodeGenerator GetLibrarySetCSharpCodeGenerator(this FluentElmToolkit fluentElmToolkit) => + fluentElmToolkit.ServiceProvider.GetRequiredService(); + + public static AssemblyCompiler GetAssemblyCompiler(this FluentElmToolkit fluentElmToolkit) => + fluentElmToolkit.ServiceProvider.GetRequiredService(); + + public static Scope CreateScope(this FluentElmToolkit fluentElmToolkit) => + new (fluentElmToolkit.ServiceProvider.CreateScope()); + + public static LibraryExpressionBuilder GetLibraryExpressionBuilder(this Scope elmFluentFluentToolkitScope) => + elmFluentFluentToolkitScope.ServiceProvider.GetRequiredService(); + + internal class Scope(IServiceScope serviceScope) : IServiceScope + { + public void Dispose() => serviceScope.Dispose(); + public IServiceProvider ServiceProvider => serviceScope.ServiceProvider; + } + + private static Library Library { get; } = new(identifier: new VersionedIdentifier { id = "Lambdas", version = "1.0.0" }); + + internal static DefinitionDictionary ProcessLibrary( + this FluentElmToolkit elmToolkit, + Library library) + { + using var scope = elmToolkit.CreateScope(); + var libraryExpressionBuilder = scope.GetLibraryExpressionBuilder(); + return libraryExpressionBuilder.ProcessLibrary(library); + } + + internal static LambdaExpression Lambda( + this FluentElmToolkit elmToolkit, + Expression expression) + { + using var scope = elmToolkit.CreateScope(); + var libraryExpressionBuilder = scope.GetLibraryExpressionBuilder(); + + DefinitionDictionary lambdas = new DefinitionDictionary(); + var ctx = libraryExpressionBuilder.NewExpressionBuilderContext(Library, lambdas); + System.Linq.Expressions.Expression translated = ctx.TranslateArg(expression); + var contextParameter = CqlExpressions.ParameterExpression; + LambdaExpression lambda = System.Linq.Expressions.Expression.Lambda(translated, contextParameter); + return lambda; + } + + +} \ No newline at end of file diff --git a/Cql/CqlToElmTests/TestExtensions.cs b/Cql/CqlToElmTests/TestExtensions.cs index c4b40f3ed..69bae8b42 100644 --- a/Cql/CqlToElmTests/TestExtensions.cs +++ b/Cql/CqlToElmTests/TestExtensions.cs @@ -1,13 +1,5 @@ -using CqlSdkPrototype.Cql; -using CqlSdkPrototype.Cql.Extensibility; -using CqlSdkPrototype.Cql.Extensions; -using CqlSdkPrototype.Elm; -using CqlSdkPrototype.Elm.Internal; -using CqlSdkPrototype.Infrastructure; using FluentAssertions.Collections; -using Hl7.Cql.Compiler; using Hl7.Cql.Elm; -using Hl7.Cql.Runtime; using Expression = Hl7.Cql.Elm.Expression; using M = Hl7.Cql.Model; @@ -15,93 +7,9 @@ namespace Hl7.Cql.CqlToElm.Test; internal static class TestExtensions { - private static CqlLibraryString FHIRHelpers { get; } = CqlLibraryString.Parse(File.ReadAllText(@"Input\FHIRHelpers-4.0.1.cql")); - - private static Library Library { get; } = new(identifier: new VersionedIdentifier { id = "Lambdas", version = "1.0.0" }); - - public static CqlApi AddFHIRHelpers(this CqlApi cqlApi) => cqlApi.AddCqlLibraryString(FHIRHelpers); - - public static Library MakeLibrary( - this CqlApi cqlApi, - string cql, - params string[] expectedErrors) - { - var cqlLibraryString = CqlLibraryString.Parse(cql); - - var library = cqlApi - .AddCqlLibraryString(cqlLibraryString) - .Translate() - .AsExtendable() - .Entries[cqlLibraryString.VersionedLibraryIdentifier] - .ElmLibrary!; - - if (expectedErrors.Any()) - library.ShouldReportError(expectedErrors); - else - library.ShouldSucceed(); - - return library; - } - - public static Library MakeLibraryFromExpression( - this CqlApi cqlApi, - string expression, - string[]? expectedErrors = null, - [System.Runtime.CompilerServices.CallerMemberName] string memberName = "") - { - string cql = $""" - library Test version '1.0.0' - - define private "{memberName}": {expression} - """; - var lib = cqlApi.MakeLibrary(cql, expectedErrors ?? []); - return lib; - } - - internal static DefinitionDictionary ProcessLibrary( - this ElmApi elmApi, - Library library) - { - using var scope = elmApi - .AsInternal() - .State - .ServiceProvider - .CreateScope(); - var libraryExpressionBuilder = scope.ServiceProvider.GetRequiredService(); - return libraryExpressionBuilder.ProcessLibrary(library); - } - - internal static LambdaExpression Lambda( - this ElmApi elmApi, - Expression expression) - { - using var scope = elmApi - .AsInternal() - .State - .ServiceProvider - .CreateScope(); - var libraryExpressionBuilder = scope.ServiceProvider.GetRequiredService(); - - DefinitionDictionary lambdas = new DefinitionDictionary(); - var ctx = libraryExpressionBuilder.NewExpressionBuilderContext(Library, lambdas); - System.Linq.Expressions.Expression translated = ctx.TranslateArg(expression); - var contextParameter = CqlExpressions.ParameterExpression; - LambdaExpression lambda = System.Linq.Expressions.Expression.Lambda(translated, contextParameter); - return lambda; - } - internal static NamedTypeSpecifier ForFhir(string typeName) => new() { name = M.QualifiedName.MakeQualifiedTypeName(M.Models.Fhir401, typeName) }; public static A ContainSingleOfType(this GenericCollectionAssertions assertions) => (A)(object)assertions.AllBeOfType().And.ContainSingle().Subject!; - - public static Expression Expression( - this CqlApi cqlApi, - string expression, - [System.Runtime.CompilerServices.CallerMemberName] - string memberName = "") - { - return cqlApi.MakeLibraryFromExpression(expression, memberName: memberName).statements[0].expression; - } } \ No newline at end of file diff --git a/Cql/PackagerCLI/PackagerCli.cs b/Cql/PackagerCLI/PackagerCli.cs index 93e4b14b4..36e544a77 100644 --- a/Cql/PackagerCLI/PackagerCli.cs +++ b/Cql/PackagerCLI/PackagerCli.cs @@ -7,10 +7,11 @@ */ using CqlSdkPrototype.Cql; -using CqlSdkPrototype.Cql.Extensions; +using CqlSdkPrototype.Cql.Fluent; +using CqlSdkPrototype.Cql.Fluent.Extensions; using CqlSdkPrototype.Elm; -using CqlSdkPrototype.Elm.Extensibility; -using CqlSdkPrototype.Elm.Extensions; +using CqlSdkPrototype.Elm.Fluent; +using CqlSdkPrototype.Elm.Fluent.Extensions; using Hl7.Cql.CodeGeneration.NET; using Hl7.Cql.Compiler; using Hl7.Cql.Packaging; @@ -19,7 +20,8 @@ namespace Hl7.Cql.Packager; -internal class PackagerCli( +internal class PackagerCli +( ILoggerFactory loggerFactory, ILogger logger, OptionsConsoleDumper optionsConsoleDumper, @@ -34,76 +36,77 @@ public int Run(bool translateCql = false) optionsConsoleDumper.DumpToConsole(); var opt = packagerCliOptions.Value; - ElmApi elmApi; + FluentElmToolkit elmToolkit; if (translateCql) { - elmApi = new CqlApi( - loggerFactory, - new CqlApiOptions(ProcessBatchItemExceptionHandling: IgnoreExceptionAndContinue)) - .OnValueSelect( - valueSelector: _ => opt.CqlInDirectory, - ifHasValue: (api, cql) => api.AddCqlLibrariesFromDirectory(cql), - ifNoValue: _ => logger.LogWarning("No input directory specified for ELM. Nothing to do.")) - .Translate() - .OnValueSelect( - valueSelector: _ => opt.ElmOutDirectory, - ifHasValue: (api, elm) => - { - elm.Recreate(); - api.SaveElmFileToDirectory(elm); - }, - ifNoValue: _ => logger.LogInformation("No out directory specified for ELM.")) - .Compile(); + var cqlToElmProcessorSettings = new CqlToElmTranslatorConfig(ProcessBatchItemExceptionHandling: IgnoreExceptionAndContinue); + elmToolkit = new FluentCqlToolkit( + loggerFactory, + cqlToElmProcessorSettings) + .PickValueAndSwitch( + valueSelector: _ => opt.CqlInDirectory, + ifHasValue: (api, cql) => api.AddCqlLibrariesFromDirectory(cql), + ifNoValue: _ => logger.LogWarning("No input directory specified for ELM. Nothing to do.")) + .TranslateCqlToElm() + .PickValueAndSwitch( + valueSelector: _ => opt.ElmOutDirectory, + ifHasValue: (api, elm) => + { + elm.Recreate(); + api.SaveElmFilesToDirectory(elm); + }, + ifNoValue: _ => logger.LogInformation("No out directory specified for ELM.")) + .CompileCqlToAssemblies(); } else { - elmApi = new ElmApi(loggerFactory, new ElmApiOptions(ProcessBatchItemExceptionHandling: IgnoreExceptionAndContinue)) - .OnValueSelect( - _ => opt.ElmInDirectory, - ifHasValue: (api, elm) => api.AddElmFilesFromDirectory(elm, filePredicate: file => !HardCodedSkipElmFiles.FileNames.Contains(file.Name)), - ifNoValue: _ => logger.LogWarning("No input directory specified for ELM. Nothing to do.")) - .Compile(); + var elmToolkitSettings = new ElmToAssemblyCompilerConfig(ProcessBatchItemExceptionHandling: IgnoreExceptionAndContinue); + elmToolkit = new FluentElmToolkit(loggerFactory, elmToolkitSettings) + .PickValueAndSwitch( + _ => opt.ElmInDirectory, + ifHasValue: (api, elm) => + api.AddElmFilesFromDirectory(elm, filePredicate: file => !HardCodedSkipElmFiles.FileNames.Contains(file.Name)), + ifNoValue: _ => logger.LogWarning("No input directory specified for ELM. Nothing to do.")) + .CompileElmToAssemblies(); } if (opt.CSharpOutDirectory is { } dirOutCS - && elmApi.AsExtendable().Entries.Any(e => e.Value.CSharpSourceCode is not null)) + && elmToolkit.ElmToAssemblyCompilations.Any(e => e.Value.CSharpSourceCode is not null)) { dirOutCS.Recreate(); - elmApi.SaveCSharpFilesToDirectory(dirOutCS); + elmToolkit.SaveCSharpFilesToDirectory(dirOutCS); } if (opt.AssemblyOutDirectory is { } dirOutDll - && elmApi.AsExtendable().Entries.Any(e => e.Value.AssemblyBinary is not null)) + && elmToolkit.ElmToAssemblyCompilations.Any(e => e.Value.AssemblyBinary is not null)) { dirOutDll.Recreate(); - elmApi.SaveAssemblyBinariesToDirectory(dirOutDll); + elmToolkit.SaveAssemblyBinariesToDirectory(dirOutDll); } if (opt is - // Check that we have all the required options - { - CqlInDirectory: { } cqlInDir, - ElmInDirectory: { } elmInDir, - FhirOutDirectory: { } fhirOutDir, - FhirCanonicalRootUrl: var canonicalRootUrl, - FhirOverrideDate: var overrideDate - } - // Check that we have the libraries produced by the ElmApi - && elmApi.AsExtendable() - .Entries - .Select(e => e.Value.ElmLibrary) - .ToArray() is {Length:>0} libraries - // Check that we have the assemblies produced by the ElmApi - && elmApi.AsExtendable() - .Entries - .Where(e => e.Value is {AssemblyBinary: { }, CSharpSourceCode: { }}) - .ToDictionary( - e => e.Key.ToString(), - e => new AssemblyDataWithSourceCode( - assemblyBytes: e.Value.AssemblyBinary!, - sourceCodeFileName: "", // Won't get used - sourceCode: e.Value.CSharpSourceCode!, - debugSymbolsBytes: e.Value.DebugSymbolsBinary)) is {} assembliesByLibraryName) + // Check that we have all the required options + { + CqlInDirectory: { } cqlInDir, + ElmInDirectory: { } elmInDir, + FhirOutDirectory: { } fhirOutDir, + FhirCanonicalRootUrl: var canonicalRootUrl, + FhirOverrideDate: var overrideDate + } + // Check that we have the libraries produced by the ElmToolkit + && elmToolkit.ElmToAssemblyCompilations + .Select(e => e.Value.ElmLibrary) + .ToArray() is { Length: > 0 } libraries + // Check that we have the assemblies produced by the ElmToolkit + && elmToolkit.ElmToAssemblyCompilations + .Where(e => e.Value is { AssemblyBinary: { }, CSharpSourceCode: { } }) + .ToDictionary( + e => e.Key.ToString(), + e => new AssemblyBinaryWithSourceCode( + assemblyBytes: e.Value.AssemblyBinary!, + sourceCodeFileName: "", // Won't get used + sourceCode: e.Value.CSharpSourceCode!, + debugSymbolsBytes: e.Value.DebugSymbolsBinary)) is { } assembliesByLibraryName) { _ = resourcePackager; LibrarySet elmLibrarySet = new LibrarySet("", libraries); @@ -133,7 +136,7 @@ public int Run(bool translateCql = false) file static class X { - public static TSelf OnValueSelect( + public static TSelf PickValueAndSwitch( this TSelf self, Func valueSelector, Action? ifHasValue = null, diff --git a/Demo/API/API.csproj b/Demo/API/API.csproj deleted file mode 100644 index 719256dcc..000000000 --- a/Demo/API/API.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - Exe - net8.0 - enable - enable - - - - - - - - - - - diff --git a/Demo/API/Program.cs b/Demo/API/Program.cs deleted file mode 100644 index 5de0e9f4d..000000000 --- a/Demo/API/Program.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Diagnostics; -using CqlSdkPrototype.Cql; -using CqlSdkPrototype.Cql.Extensions; -using CqlSdkPrototype.Elm.Extensions; -using CqlSdkPrototype.Infrastructure; -using CqlSdkPrototype.Runtime.Extensions; -using Hl7.Cql.Fhir; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace API; - -internal static class Program -{ - private static void Main(string[] args) - { - //Setup DI - var services = new ServiceCollection(); - - services.AddLogging(builder => builder.AddConsole()); - - services.AddSingleton(new CqlApiOptions(Models: [CqlModel.ElmR1, CqlModel.Fhir401])); - services.AddSingleton(); - - // Get CqlApi from DI - IServiceProvider serviceProvider = services.BuildServiceProvider(); - var cqlApi = serviceProvider.GetRequiredService(); - - // Setup and use CqlApi - cqlApi.AddCqlLibrariesFromDirectory(new DirectoryInfo("input/cql/")); - cqlApi.Translate(); - cqlApi.SaveElmFileToDirectory(new DirectoryInfo("output/elm/")); - - // Setup and use ElmApi - var elmApi = cqlApi.CreateElmApi(); - elmApi.Compile(); - elmApi.SaveCSharpFilesToDirectory(new DirectoryInfo("output/csharp/")); - elmApi.SaveAssemblyBinariesToDirectory(new DirectoryInfo("output/assemblies/")); - - // Setup RuntimeApi - var runtimeApi = elmApi.CreateRuntimeApi(); - var runtimeScope = runtimeApi.CreateRuntimeScope(); - - // Execute CQL - var threePlusTwo = runtimeScope.GetLibraryDefinitionResult( - FhirCqlContext.ForBundle(), - CqlVersionedLibraryIdentifier.ParseFromNameAndVersion("Add3and2", "1.0.0"), - "ThreePlusTwo"); - - Debug.Assert(threePlusTwo is 5); - } -} - diff --git a/Demo/CLI/Helpers/LibraryExtensions.cs b/Demo/CLI/Helpers/LibraryExtensions.cs index c5c6b0752..40bcc3099 100644 --- a/Demo/CLI/Helpers/LibraryExtensions.cs +++ b/Demo/CLI/Helpers/LibraryExtensions.cs @@ -6,12 +6,13 @@ * available at https://raw.githubusercontent.com/FirelyTeam/firely-cql-sdk/main/LICENSE */ +using CqlSdkPrototype.Invocation; +using CqlSdkPrototype.Invocation.Fluent; using Hl7.Cql.Abstractions; +using Hl7.Cql.CodeGeneration.NET; using Hl7.Cql.Fhir; using Hl7.Cql.ValueSets; using Hl7.Fhir.Model; -using CqlSdkPrototype.Runtime; -using Hl7.Cql.CodeGeneration.NET; using Hl7.Cql.Packaging; using Library = Hl7.Fhir.Model.Library; @@ -81,20 +82,20 @@ bool TryLoadArtifactAndDependencies(RelatedArtifact relatedArtifact) } } - public static RuntimeScope CreateRuntimeScope( + public static LibrarySetInvoker ToLibrarySetInvoker( this IEnumerable libraries) { - var assemblyDatas = + var assemblyBinaries = libraries .Select(library => library.Content.SingleOrDefault(att => att.ContentType == "application/octet-stream")) .OfType() .Select(dll => dll.Data) - .Select(assemblyBytes => AssemblyData.Default with { AssemblyBytes = assemblyBytes}) + .Select(assemblyBytes => AssemblyBinary.Default with { AssemblyBytes = assemblyBytes}) .ToArray(); - return new RuntimeApi() - .AddAssemblies(assemblyDatas) - .CreateRuntimeScope(); + return new FluentInvocationToolkit() + .AddAssemblyBinaries(assemblyBinaries) + .ToLibrarySetInvoker(); } private static Dictionary> GetValueSets(Type libraryType) diff --git a/Demo/CLI/Helpers/ResourceHelper.cs b/Demo/CLI/Helpers/ResourceHelper.cs index 5a5ffec77..508f50d24 100644 --- a/Demo/CLI/Helpers/ResourceHelper.cs +++ b/Demo/CLI/Helpers/ResourceHelper.cs @@ -5,6 +5,8 @@ * This file is licensed under the BSD 3-Clause license * available at https://raw.githubusercontent.com/FirelyTeam/firely-cql-sdk/main/LICENSE */ + +using CqlSdkPrototype.Invocation; using Dumpify; using Hl7.Cql.Conversion; using Hl7.Cql.Fhir; @@ -13,7 +15,6 @@ using Hl7.Cql.ValueSets; using Hl7.Fhir.Model; using Hl7.Fhir.Serialization; -using CqlSdkPrototype.Runtime; using static Hl7.Fhir.Model.Parameters; using Library = Hl7.Fhir.Model.Library; @@ -60,7 +61,7 @@ public static IValueSetDictionary LoadValueSets(DirectoryInfo directory) return vsd; } - public static RuntimeScope CreateRuntimeScopeFromFhirLibraryFile( + public static LibrarySetInvoker CreateRuntimeScopeFromFhirLibraryFile( DirectoryInfo dir, string lib, string version) @@ -69,7 +70,7 @@ public static RuntimeScope CreateRuntimeScopeFromFhirLibraryFile( using var fs = libFile.OpenRead(); var library = fs.ParseFhir(); var deps = library.GetDependenciesAndSelf(dir); - return deps.CreateRuntimeScope(); + return deps.ToLibrarySetInvoker(); } diff --git a/Demo/CLI/LibraryRunner.cs b/Demo/CLI/LibraryRunner.cs index 832a72160..523fc25fb 100644 --- a/Demo/CLI/LibraryRunner.cs +++ b/Demo/CLI/LibraryRunner.cs @@ -1,4 +1,6 @@ using CLI.Helpers; +using CqlSdkPrototype.Invocation; +using CqlSdkPrototype.Invocation.Fluent; using Dumpify; using Hl7.Cql.Abstractions; using Hl7.Cql.Fhir; @@ -6,8 +8,8 @@ using Hl7.Cql.ValueSets; using Hl7.Fhir.Model; using Hl7.Fhir.Serialization; -using CqlSdkPrototype.Runtime; using Hl7.Cql.CodeGeneration.NET; +using CqlSdkPrototype.Invocation.Fluent.Extensions; namespace CLI { @@ -30,11 +32,11 @@ public void RunWithMeasuresProject() //used for debugging with breakpoints in Measures.* project //if used in production scenario compile measures.* dll and reference it below instead, example Assembly.LoadFrom("Measures.Authoring") //see launchsettings.json - var assemblyData = AssemblyData.Default.LoadFromFiles(new FileInfo(_opts.AssemblyPath)); - using var runtimeScope = new RuntimeApi() - .AddAssemblies([assemblyData]) - .CreateRuntimeScope(); - RunShared(_opts, runtimeScope); + var assemblyBinary = AssemblyBinary.Default.LoadFromFile(new FileInfo(_opts.AssemblyPath)); + using var librarySetInvoker = new FluentInvocationToolkit() + .AddAssemblyBinaries(assemblyBinary) + .ToLibrarySetInvoker(); + RunShared(_opts, librarySetInvoker); } public void RunWithResources() @@ -46,7 +48,7 @@ public void RunWithResources() RunShared(_opts, scope); } - private void RunShared(CommandLineOptions opt, RuntimeScope runtimeScope) + private void RunShared(CommandLineOptions opt, LibrarySetInvoker librarySetInvoker) { //Type libraryType = ResolveLibraryType(opt, runtimeScope) ?? throw new ArgumentException($"Unknown library: {opt.Library}"); Console.WriteLine("Loading value sets"); diff --git a/Demo/CqlApiExamples/CqlApiExamples.csproj b/Demo/CqlApiExamples/CqlApiExamples.csproj new file mode 100644 index 000000000..a7c54862d --- /dev/null +++ b/Demo/CqlApiExamples/CqlApiExamples.csproj @@ -0,0 +1,87 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + diff --git a/Cql/CqlSdkPrototype/Internal/Directories.cs b/Demo/CqlApiExamples/Directories.cs similarity index 84% rename from Cql/CqlSdkPrototype/Internal/Directories.cs rename to Demo/CqlApiExamples/Directories.cs index a76e4b6ca..701862df0 100644 --- a/Cql/CqlSdkPrototype/Internal/Directories.cs +++ b/Demo/CqlApiExamples/Directories.cs @@ -1,4 +1,6 @@ -namespace CqlSdkPrototype.Internal; +using System.Diagnostics; + +namespace CqlApiExamples; internal class Directories(string librarySetName) { @@ -9,7 +11,7 @@ librarySetName is "Demo" or "CMS" or "Authoring" - or "Examples"); + or "Tests"); return new Directories(librarySetName); } @@ -33,13 +35,13 @@ private static DirectoryInfo FindAncestor(DirectoryInfo start, Func CurrentProjectDirectory.CreateSubdirectory("generated").CreateSubdirectory(LibrarySetName); + public DirectoryInfo GeneratedDirectory => CurrentDirectory.CreateSubdirectory("output").CreateSubdirectory(LibrarySetName); public DirectoryInfo CqlInDirectory => LibrarySetName switch { - "Examples" => CurrentProjectDirectory.CreateSubdirectory("examples"), + "Tests" => CurrentDirectory.CreateSubdirectory("input").CreateSubdirectory(LibrarySetName).CreateSubdirectory("cql"), "Authoring" => AuthoringProjectDirectory.CreateSubdirectory("Input").CreateSubdirectory("cql"), - _ => LibrarySetsDirectory.CreateSubdirectory(LibrarySetName).CreateSubdirectory("Cql") + _ => LibrarySetsDirectory.CreateSubdirectory(LibrarySetName).CreateSubdirectory("Cql") }; public DirectoryInfo ElmInDirectory => LibrarySetsDirectory.CreateSubdirectory(LibrarySetName).CreateSubdirectory("Elm"); diff --git a/Demo/CqlApiExamples/Maybe.cs b/Demo/CqlApiExamples/Maybe.cs new file mode 100644 index 000000000..ca3b528db --- /dev/null +++ b/Demo/CqlApiExamples/Maybe.cs @@ -0,0 +1,77 @@ +namespace CqlApiExamples; + +internal readonly record struct Maybe +{ + public static Maybe NoValue => default; + public static Maybe Of(T value) => new(value); +} + +internal readonly record struct Maybe(T Value) +{ + public static Maybe NoValue => default; + public static implicit operator Maybe(T? value) => value is null ? NoValue : new(value); + public static implicit operator Maybe(Maybe value) => NoValue; + + private readonly T _value = Value; + public T Value => HasValue ? _value : throw new InvalidOperationException("No value"); + + public bool HasValue { get; } = true; // Do NOT change this code to: HasValue => true + + public bool TryGetValue(out T value) + { + value = _value; + return HasValue; + } + + public void Switch( + Action? withValue = null, + Action? withoutValue = null) + { + if (TryGetValue(out var value)) + withValue?.Invoke(value); + else + withoutValue?.Invoke(); + } + + public TR Return( + Func? withValue = null, + Func? withoutValue = null, + TR defaultValue = default!) + { + var result = TryGetValue(out var value) switch + { + true when withValue is not null => withValue!(value), + false when withoutValue is not null => withoutValue!(), + _ => defaultValue + }; + return result; + } + + public Maybe TryReturn( + Func? withValue = null, + Func? withoutValue = null, + Maybe defaultValue = default!) + { + var result = TryGetValue(out var value) switch + { + true when withValue is not null => withValue!(value), + false when withoutValue is not null => withoutValue!(), + _ => defaultValue + }; + return result; + } + + public Maybe TryReturn( + Func>? withValue = null, + Func>? withoutValue = null, + Maybe defaultValue = default!) + { + var result = TryGetValue(out var value) switch + { + true when withValue is not null => withValue!(value), + false when withoutValue is not null => withoutValue!(), + _ => defaultValue + }; + return result; + } +} \ No newline at end of file diff --git a/Demo/CqlApiExamples/Program.cs b/Demo/CqlApiExamples/Program.cs new file mode 100644 index 000000000..c43f5c2bf --- /dev/null +++ b/Demo/CqlApiExamples/Program.cs @@ -0,0 +1,284 @@ +using System.Diagnostics; +using System.Text; +using CqlSdkPrototype.Cql; +using CqlSdkPrototype.Cql.Fluent; +using CqlSdkPrototype.Cql.Fluent.Extensions; +using CqlSdkPrototype.Elm.Fluent; +using CqlSdkPrototype.Elm.Fluent.Extensions; +using CqlSdkPrototype.Infrastructure; +using CqlSdkPrototype.Invocation; +using CqlSdkPrototype.Invocation.Extensions; +using CqlSdkPrototype.Invocation.Fluent.Extensions; +using Hl7.Cql.Abstractions.Exceptions; +using Hl7.Cql.CodeGeneration.NET; +using Hl7.Cql.Fhir; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace CqlApiExamples; + +using static FormattableString; + +internal static class Program +{ + private static void Main(string[] args) + { + // Create a logger factory via the Microsoft.Extensions.Logging API + var loggerFactory = CreateConsoleLoggerFactory(); + + Add3And2Example(loggerFactory); + InvokeCqlExample(loggerFactory); + InvokeCqlFromExamplesFolder(loggerFactory); + + var shouldBuildCqlToElm = true; + string[] exampleSetNames = ["CMS", "Authoring", "CMS", "Demo", "Tests"]; + foreach (var exampleSetName in exampleSetNames) + { + Directories dirs = Directories.Create(exampleSetName); + FullExample(loggerFactory, dirs, shouldBuildCqlToElm); + } + } + + private static void InvokeCqlExample( + ILoggerFactory loggerFactory) + { + // INTRO: + // This example demonstrates how to add a CqlLibraryString to the CqlToolkit and invoke a library declaration directly. + + // Create fluent cql toolkit + var cqlToElmProcessorSettings = new CqlToElmTranslatorConfig(Models: [CqlModel.ElmR1, CqlModel.Fhir401]); + FluentCqlToolkit cqlToolkit = new FluentCqlToolkit(loggerFactory, cqlToElmProcessorSettings); + + + // NICE TO HAVE: Would be nice to parse the CqlLibraryString only from the CQL and extract the identifier from the CQL + var cqlLibraryString = CqlLibraryString.Parse( + """ + library AdditionLib version '0.0.0' + + define private Three: 1 + 2 + """); + var cqlContext = FhirCqlContext.ForBundle(); + using var librarySetInvoker = cqlToolkit + .AddCqlLibraryString(cqlLibraryString) + .ToLibrarySetInvoker(elmOpt => elmOpt with + { + AssemblyCompilerDebugInformationFormat = AssemblyCompilerDebugInformationFormat.Embedded + }); + var result = librarySetInvoker.GetLibraryDefinitionResult(cqlContext, cqlLibraryString.VersionedLibraryIdentifier, "Three"); + Debug.Assert(result is 3); + } + + private static void InvokeCqlFromExamplesFolder( + ILoggerFactory loggerFactory) + { + // INTRO: + // This example demonstrates how to load CQL libraries from a directory and invoke a library declarations directly. + + var logger = loggerFactory.CreateLogger(typeof(Program)); + + // "Directories" is not a part of the API, but a helper class for this example + var dirs = Directories.Create("Tests"); + + // Create fluent cql toolkit + var cqlToElmProcessorSettings = new CqlToElmTranslatorConfig(Models: [CqlModel.ElmR1, CqlModel.Fhir401]); + FluentCqlToolkit cqlToolkit = new FluentCqlToolkit(loggerFactory, cqlToElmProcessorSettings); + + // We can write extensions to make it even easier to change exception handling + var cqlContext = FhirCqlContext.ForBundle(); + + // We need a disposable invocation scope, which contains the AssemblyLoadContext and the related library Assemblies. + using var librarySetInvoker = cqlToolkit + .Reconfigure(o => o with + { + ProcessBatchItemExceptionHandling = ProcessBatchItemExceptionHandling.IgnoreExceptionAndContinue + }) + .AddCqlLibrariesFromDirectory(dirs.CqlInDirectory) + .ToLibrarySetInvoker(); + logger.LogInformation("{dump}", librarySetInvoker.DumpLibraryDeclarations()); + Debug.Assert(Invoke("CqlAggregateFunctionsTest-1.0.000", "Count.CountTestTime") is 3); + Debug.Assert(Invoke("CqlAggregateFunctionsTest-1.0.000", "Count.CountTestNull") is 0); + Debug.Assert(Invoke("CqlStringOperatorsTest-1.0.000", "Combine.CombineABCSepDash") is "a-b-c"); + + object? Invoke(string libraryName, string declarationName) + { + var libraryIdentifier = CqlVersionedLibraryIdentifier.Parse(libraryName); + var result = librarySetInvoker.GetLibraryDefinitionResult(cqlContext, libraryIdentifier, declarationName); + return result; + } + } + + private static void FullExample( + ILoggerFactory loggerFactory, + Directories dirs, + bool shouldBuildCqlToElm = false) + { + // INTRO: + // This example loads the CQL libraries, translates them to ELM, and compiles them to assemblies. + // Each intermediate format is saved to directory (e.g. ELM, C#, and assembly binaries with their debug symbols). + // It also demonstrates how to execute a library. + + var logger = loggerFactory.CreateLogger(typeof(Program)); + dirs.GeneratedDirectory.Delete(recursive: true); + + // Create fluent cql toolkit + var cqlToElmProcessorSettings = new CqlToElmTranslatorConfig(Models: [CqlModel.ElmR1, CqlModel.Fhir401]); + FluentCqlToolkit cqlToolkit = + new FluentCqlToolkit(loggerFactory, cqlToElmProcessorSettings) + .ConfigIgnoreExceptions(); + + if (shouldBuildCqlToElm) + { + cqlToolkit + .AddCqlLibrariesFromDirectory(dirs.CqlInDirectory) + .TranslateCqlToElm() + .SaveElmFilesToDirectory(dirs.ElmOutDirectory) + ; + } + + var elmToolkit = cqlToolkit + .ToFluentElmToolkit() + .ConfigAssemblyDebugInformationToEmbedded() + .AddElmFilesFromDirectory(dirs.ElmInDirectory) + .CompileElmToAssemblies() + .SaveCSharpFilesToDirectory(dirs.CSharpOutDirectory) + .SaveAssemblyBinariesToDirectory(dirs.AssembliesOutDirectory); + + cqlToolkit.TryGetFirstElmFileLines() + .Switch(t => logger.LogInformation( + $""" + First 50 ELM lines for {t.id}: + {t.elmJson.TakeLines(50)} + """)); + + elmToolkit.TryGetFirstCSharpFileLines() + .Switch(t => logger.LogInformation( + $""" + First 50 C# lines for {t.id}: + {t.cSharpSourceCode.TakeLines(50)} + """)); + } + + + private static void Add3And2Example( + ILoggerFactory loggerFactory) + { + // Create fluent cql toolkit + var cqlToElmProcessorSettings = new CqlToElmTranslatorConfig(Models: [CqlModel.ElmR1, CqlModel.Fhir401]); + FluentCqlToolkit cqlToolkit = new FluentCqlToolkit(loggerFactory, cqlToElmProcessorSettings); + + // Add CQL libraries from a directory and process them to ELM, then save the ELM files to a directory + cqlToolkit + .AddCqlLibrariesFromDirectory(new DirectoryInfo("input/1/cql")) + .TranslateCqlToElm() + .SaveElmFilesToDirectory(new DirectoryInfo("output/1/elm/")); + + // Create fluent elm toolkit as a continuation of the cql toolkit + var elmToolkit = cqlToolkit.ToFluentElmToolkit(); + + // Process the ELM files to assemblies, then save the C# files and assembly binaries to directories + elmToolkit + .CompileElmToAssemblies() // TODO:ConvertElmToAssemblies + .SaveCSharpFilesToDirectory(new DirectoryInfo("output/1/csharp/")) + .SaveAssemblyBinariesToDirectory(new DirectoryInfo("output/1/assemblies/")); + + // Setup RuntimeApi + var invocationToolkit = elmToolkit.ToFluentInvocationToolkit(); + using var librarySetInvoker = invocationToolkit.ToLibrarySetInvoker(); // NOTE: 'librarySetInvoker' is a disposable object! + + // Execute CQL + var threePlusTwo = librarySetInvoker.GetLibraryDefinitionResult( + FhirCqlContext.ForBundle(), + CqlVersionedLibraryIdentifier.ParseFromNameAndVersion("Add3and2", "1.0.0"), + "ThreePlusTwo"); + + Debug.Assert(threePlusTwo is 5); + } + + private static ILoggerFactory CreateConsoleLoggerFactory() + { + var services = new ServiceCollection(); + services.AddLogging(builder => builder.AddConsole()); + IServiceProvider serviceProvider = services.BuildServiceProvider(); + var loggerFactory = serviceProvider.GetRequiredService(); + return loggerFactory; + } +} + +file static class Extensions +{ + internal static StringBuilder DumpLibraryDeclarations( + this LibrarySetInvoker scope, + StringBuilder? sb = null) + { + sb ??= new(); + sb.AppendLine("Libraries and Declarations:"); + foreach (var (libId, lib) in scope.LibraryInvokers) + { + sb.AppendLine(Invariant($"- {libId}")); + foreach (var (declId, decl) in lib.Definitions) + sb.AppendLine(Invariant($" - {declId} : {decl.ReturnType}")); + } + + return sb; + } + + public static string[] SplitLines(this string multilineString) => + multilineString.Split([Environment.NewLine], StringSplitOptions.None); + + public static string JoinLines(this IEnumerable lines) => + string.Join(Environment.NewLine, lines); + + public static string TakeLines(this string multilineString, int count) => + multilineString.SplitLines().Take(count).JoinLines(); + + public static Maybe TryGetFirst(this IEnumerable source) + { + if (source == null) + throw new ArgumentNullException(nameof(source)); + + if (source is IList list) + { + if (list.Count > 0) + { + return list[0]; + } + } + else + { + using IEnumerator e = source.GetEnumerator(); + if (e.MoveNext()) + { + return e.Current; + } + } + + return Maybe.NoValue; + } + + public static Maybe TryGetFirst(this IEnumerable source, Func predicate) + { + if (source == null) + throw new ArgumentNullException(nameof(source)); + + foreach (TSource element in source) + { + if (predicate(element)) + { + return element; + } + } + + return Maybe.NoValue; + } + + public static Maybe<(CqlVersionedLibraryIdentifier id, string cSharpSourceCode)> TryGetFirstCSharpFileLines(this FluentElmToolkit elmToolkit) => + elmToolkit.ElmToAssemblyCompilations + .TryGetFirst(kv => kv.Value.CSharpSourceCode is not null) + .TryReturn(kv => (kv.Key, kv.Value.CSharpSourceCode!)); + + public static Maybe<(CqlVersionedLibraryIdentifier id, string elmJson)> TryGetFirstElmFileLines( + this FluentCqlToolkit cqlToolkit) => + cqlToolkit.CqlToElmTranslations + .TryGetFirst(kv => kv.Value.ElmLibrary is not null) + .TryReturn(kv => (kv.Key, kv.Value.ElmLibrary!.SerializeToJson()!)); +} \ No newline at end of file diff --git a/Demo/API/input/cql/Add3and2.cql b/Demo/CqlApiExamples/input/Add/cql/Add3and2.cql similarity index 100% rename from Demo/API/input/cql/Add3and2.cql rename to Demo/CqlApiExamples/input/Add/cql/Add3and2.cql diff --git a/Cql/CqlSdkPrototype/examples/CqlAggregateFunctionsTest-1.0.000.cql b/Demo/CqlApiExamples/input/Tests/cql/CqlAggregateFunctionsTest-1.0.000.cql similarity index 100% rename from Cql/CqlSdkPrototype/examples/CqlAggregateFunctionsTest-1.0.000.cql rename to Demo/CqlApiExamples/input/Tests/cql/CqlAggregateFunctionsTest-1.0.000.cql diff --git a/Cql/CqlSdkPrototype/examples/CqlAggregateTest-1.0.000.cql b/Demo/CqlApiExamples/input/Tests/cql/CqlAggregateTest-1.0.000.cql similarity index 100% rename from Cql/CqlSdkPrototype/examples/CqlAggregateTest-1.0.000.cql rename to Demo/CqlApiExamples/input/Tests/cql/CqlAggregateTest-1.0.000.cql diff --git a/Cql/CqlSdkPrototype/examples/CqlArithmeticFunctionsTest-1.0.000.cql b/Demo/CqlApiExamples/input/Tests/cql/CqlArithmeticFunctionsTest-1.0.000.cql similarity index 100% rename from Cql/CqlSdkPrototype/examples/CqlArithmeticFunctionsTest-1.0.000.cql rename to Demo/CqlApiExamples/input/Tests/cql/CqlArithmeticFunctionsTest-1.0.000.cql diff --git a/Cql/CqlSdkPrototype/examples/CqlComparisonOperatorsTest-1.0.000.cql b/Demo/CqlApiExamples/input/Tests/cql/CqlComparisonOperatorsTest-1.0.000.cql similarity index 100% rename from Cql/CqlSdkPrototype/examples/CqlComparisonOperatorsTest-1.0.000.cql rename to Demo/CqlApiExamples/input/Tests/cql/CqlComparisonOperatorsTest-1.0.000.cql diff --git a/Cql/CqlSdkPrototype/examples/CqlConditionalOperatorsTest-1.0.000.cql b/Demo/CqlApiExamples/input/Tests/cql/CqlConditionalOperatorsTest-1.0.000.cql similarity index 100% rename from Cql/CqlSdkPrototype/examples/CqlConditionalOperatorsTest-1.0.000.cql rename to Demo/CqlApiExamples/input/Tests/cql/CqlConditionalOperatorsTest-1.0.000.cql diff --git a/Cql/CqlSdkPrototype/examples/CqlDateTimeOperatorsTest-1.0.000.cql b/Demo/CqlApiExamples/input/Tests/cql/CqlDateTimeOperatorsTest-1.0.000.cql similarity index 100% rename from Cql/CqlSdkPrototype/examples/CqlDateTimeOperatorsTest-1.0.000.cql rename to Demo/CqlApiExamples/input/Tests/cql/CqlDateTimeOperatorsTest-1.0.000.cql diff --git a/Cql/CqlSdkPrototype/examples/CqlErrorsAndMessagingOperatorsTest-1.0.000.cql b/Demo/CqlApiExamples/input/Tests/cql/CqlErrorsAndMessagingOperatorsTest-1.0.000.cql similarity index 100% rename from Cql/CqlSdkPrototype/examples/CqlErrorsAndMessagingOperatorsTest-1.0.000.cql rename to Demo/CqlApiExamples/input/Tests/cql/CqlErrorsAndMessagingOperatorsTest-1.0.000.cql diff --git a/Cql/CqlSdkPrototype/examples/CqlIntervalOperatorsTest-1.0.000.cql b/Demo/CqlApiExamples/input/Tests/cql/CqlIntervalOperatorsTest-1.0.000.cql similarity index 100% rename from Cql/CqlSdkPrototype/examples/CqlIntervalOperatorsTest-1.0.000.cql rename to Demo/CqlApiExamples/input/Tests/cql/CqlIntervalOperatorsTest-1.0.000.cql diff --git a/Cql/CqlSdkPrototype/examples/CqlListOperatorsTest-1.0.000.cql b/Demo/CqlApiExamples/input/Tests/cql/CqlListOperatorsTest-1.0.000.cql similarity index 100% rename from Cql/CqlSdkPrototype/examples/CqlListOperatorsTest-1.0.000.cql rename to Demo/CqlApiExamples/input/Tests/cql/CqlListOperatorsTest-1.0.000.cql diff --git a/Cql/CqlSdkPrototype/examples/CqlLogicalOperatorsTest-1.0.000.cql b/Demo/CqlApiExamples/input/Tests/cql/CqlLogicalOperatorsTest-1.0.000.cql similarity index 100% rename from Cql/CqlSdkPrototype/examples/CqlLogicalOperatorsTest-1.0.000.cql rename to Demo/CqlApiExamples/input/Tests/cql/CqlLogicalOperatorsTest-1.0.000.cql diff --git a/Cql/CqlSdkPrototype/examples/CqlNullologicalOperatorsTest-1.0.000.cql b/Demo/CqlApiExamples/input/Tests/cql/CqlNullologicalOperatorsTest-1.0.000.cql similarity index 100% rename from Cql/CqlSdkPrototype/examples/CqlNullologicalOperatorsTest-1.0.000.cql rename to Demo/CqlApiExamples/input/Tests/cql/CqlNullologicalOperatorsTest-1.0.000.cql diff --git a/Cql/CqlSdkPrototype/examples/CqlStringOperatorsTest-1.0.000.cql b/Demo/CqlApiExamples/input/Tests/cql/CqlStringOperatorsTest-1.0.000.cql similarity index 100% rename from Cql/CqlSdkPrototype/examples/CqlStringOperatorsTest-1.0.000.cql rename to Demo/CqlApiExamples/input/Tests/cql/CqlStringOperatorsTest-1.0.000.cql diff --git a/Cql/CqlSdkPrototype/examples/CqlTypeOperatorsTest-1.0.000.cql b/Demo/CqlApiExamples/input/Tests/cql/CqlTypeOperatorsTest-1.0.000.cql similarity index 100% rename from Cql/CqlSdkPrototype/examples/CqlTypeOperatorsTest-1.0.000.cql rename to Demo/CqlApiExamples/input/Tests/cql/CqlTypeOperatorsTest-1.0.000.cql diff --git a/Cql/CqlSdkPrototype/examples/CqlTypesTest-1.0.000.cql b/Demo/CqlApiExamples/input/Tests/cql/CqlTypesTest-1.0.000.cql similarity index 100% rename from Cql/CqlSdkPrototype/examples/CqlTypesTest-1.0.000.cql rename to Demo/CqlApiExamples/input/Tests/cql/CqlTypesTest-1.0.000.cql diff --git a/Cql/CqlSdkPrototype/examples/ValueLiteralsAndSelectors-1.0.000.cql b/Demo/CqlApiExamples/input/Tests/cql/ValueLiteralsAndSelectors-1.0.000.cql similarity index 100% rename from Cql/CqlSdkPrototype/examples/ValueLiteralsAndSelectors-1.0.000.cql rename to Demo/CqlApiExamples/input/Tests/cql/ValueLiteralsAndSelectors-1.0.000.cql diff --git a/Demo/Measures.CMS/Measures.CMS.csproj b/Demo/Measures.CMS/Measures.CMS.csproj index d2f3d801f..cb25090ca 100644 --- a/Demo/Measures.CMS/Measures.CMS.csproj +++ b/Demo/Measures.CMS/Measures.CMS.csproj @@ -19,6 +19,8 @@ $(CqlSolutionDir)LibrarySets/$(LibrarySet) $(LibrarySetRoot)/Cql $(LibrarySetRoot)/Elm + + $(CqlSolutionDir)/submodules/Firely.Cql.Sdk.Integration.Runner/IntegrationRunner/CMS Assemblies $(LibrarySetRoot)/Resources $(MSBuildProjectDirectory)/input/tests/results diff --git a/Demo/Test.Measures.Demo/MeasuresTest.cs b/Demo/Test.Measures.Demo/MeasuresTest.cs index 3c7537dbc..72e606efc 100644 --- a/Demo/Test.Measures.Demo/MeasuresTest.cs +++ b/Demo/Test.Measures.Demo/MeasuresTest.cs @@ -5,11 +5,13 @@ using Hl7.Cql.Compiler; using CLI.Helpers; using CqlSdkPrototype.Elm; -using CqlSdkPrototype.Runtime; -using CqlSdkPrototype.Runtime.Extensions; +using CqlSdkPrototype.Elm.Fluent; using Hl7.Cql.CodeGeneration.NET; using Hl7.Cql.Runtime; using CqlSdkPrototype.Infrastructure; +using CqlSdkPrototype.Invocation; +using CqlSdkPrototype.Invocation.Extensions; +using CqlSdkPrototype.Invocation.Fluent.Extensions; namespace Test { @@ -53,7 +55,7 @@ public void BCSEHEDIS2022_Numerator_FromResource_Passed() var results = scope .EnumerateLibraryDefinitionsResults(ctx, CqlVersionedLibraryIdentifier.FromNameAndVersion(CqlLibraryIdentifier.Parse(lib), CqlLibraryVersion.Parse(version))) - .ToDictionary(t => t.definition, t => t.getResult()); + .ToDictionary(t => t.definitionInvoker.DefinitionName, t => t.getResult()); Assert.IsTrue(results.TryGetValue("Numerator", out var numerator)); Assert.IsInstanceOfType(numerator, typeof(bool?)); @@ -103,18 +105,17 @@ public void BCSEHEDIS2022_Numerator_FromElm() } private static IReadOnlyDictionary Run( - RuntimeScope scope, + LibrarySetInvoker scope, string lib, string version, CqlContext context) { return scope .EnumerateLibraryDefinitionsResults(context, CqlVersionedLibraryIdentifier.Parse($"{lib}-{version}")) - .ToDictionary(t => t.definition, t => t.getResult()); + .ToDictionary(t => t.definitionInvoker.DefinitionName, t => t.getResult()); } - [UsedImplicitly] - public static RuntimeScope CreateRuntimeScopeFromFhirResourceFile( + private static LibrarySetInvoker CreateRuntimeScopeFromFhirResourceFile( DirectoryInfo dir, string lib, string version) @@ -124,41 +125,47 @@ public static RuntimeScope CreateRuntimeScopeFromFhirResourceFile( var library = fs.ParseFhir(); var allLibs = library.GetDependenciesAndSelf(dir); //Runtime - return allLibs.CreateRuntimeScope(); + return allLibs.ToLibrarySetInvoker(); } - [UsedImplicitly] - public static RuntimeScope CreateRuntimeScopeFromElmLibraryFile( + private static LibrarySetInvoker CreateRuntimeScopeFromElmLibraryFile( DirectoryInfo elmDirectory, string lib, string version, LogLevel logLevel = LogLevel.Error, int cacheSize = 0) { - return CreateRuntimeScopeFromElmLibraryFile(elmDirectory, lib, version, cacheSize); + var loggerFactory = new ServiceCollection() + .AddLogging(builder => builder.AddConsole().SetMinimumLevel(logLevel)) + .BuildServiceProvider() + .GetRequiredService(); + + return CreateRuntimeScopeFromElmLibraryFile(elmDirectory, lib, version, cacheSize, loggerFactory); } - [UsedImplicitly] - public static RuntimeScope CreateRuntimeScopeFromElmLibraryFile( + private static LibrarySetInvoker CreateRuntimeScopeFromElmLibraryFile( DirectoryInfo elmDirectory, string lib, string version, int cacheSize, - ILoggerFactory? loggerFactory = null, - Func? configureOptions = null) + ILoggerFactory? loggerFactory = null/*, + Func? configureLibrarySetInvokerBuilder = null*/) { - Trace.Assert(cacheSize == 0, "TODO: CacheSize must still be moved to configuration"); // TODO: CacheSize must still be moved to configuration LibrarySet librarySet = new(); librarySet.LoadLibraryAndDependencies(elmDirectory, lib, version); - var elmApiOptions = ElmApiOptions.Default; + var config = ElmToAssemblyCompilerConfig.Default; + if (cacheSize != 0) + config = config with { LRUCacheSize = cacheSize }; + if (Debugger.IsAttached) - elmApiOptions = elmApiOptions with { AssemblyCompilerDebugInformationFormat = AssemblyCompilerDebugInformationFormat.Embedded }; - var elmApi = new ElmApi(loggerFactory, elmApiOptions); + config = config with { AssemblyCompilerDebugInformationFormat = AssemblyCompilerDebugInformationFormat.Embedded }; + + var elmToolkit = new FluentElmToolkit(loggerFactory, config); - return elmApi - .AddElmLibraries(librarySet) - .CreateRuntimeScope(configureOptions); + return elmToolkit + .AddElmLibraries(librarySet) + .ToLibrarySetInvoker(/*configure: configureLibrarySetInvokerBuilder*/); } } } \ No newline at end of file diff --git a/Demo/cql-demo.props b/Demo/cql-demo.props index ab6d21317..c543b548b 100644 --- a/Demo/cql-demo.props +++ b/Demo/cql-demo.props @@ -35,7 +35,8 @@ false - true + false + true diff --git a/cql-base.props b/cql-base.props index 13c645892..afcc70567 100644 --- a/cql-base.props +++ b/cql-base.props @@ -31,7 +31,8 @@ false - true + false + true diff --git a/submodules/Firely.Cql.Sdk.Integration.Runner b/submodules/Firely.Cql.Sdk.Integration.Runner index 1c574cdca..559b2c24f 160000 --- a/submodules/Firely.Cql.Sdk.Integration.Runner +++ b/submodules/Firely.Cql.Sdk.Integration.Runner @@ -1 +1 @@ -Subproject commit 1c574cdcab89592e24eaa97b6432a75c78209ce2 +Subproject commit 559b2c24fdebf995639c27e72dce8de478e04b7e diff --git a/submodules/Ncqa.DQIC b/submodules/Ncqa.DQIC index f2705bdc4..b74c66915 160000 --- a/submodules/Ncqa.DQIC +++ b/submodules/Ncqa.DQIC @@ -1 +1 @@ -Subproject commit f2705bdc49fc70d2fb36c5f1f779f2e69ad4384b +Subproject commit b74c66915ae4841daa051a23bb36d1854965a655