From b9f7ad323b75e28d10dfd56d664fb0cad885b960 Mon Sep 17 00:00:00 2001 From: JP Date: Fri, 20 Dec 2024 13:53:15 -0700 Subject: [PATCH] Change default signature level from None to Overloads (#1481) * Change default signature level from None to Overloads * Fix tests * Remove potential thrown exception from Lambda --- .../cql/cql2elm/CqlCompilerOptions.java | 2 +- .../org/cqframework/cql/cql2elm/options.json | 2 +- .../cql/engine/fhir/data/TestFHIRHelpers.java | 29 +++++++++---------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/CqlCompilerOptions.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/CqlCompilerOptions.java index 11bae46ce..27f179744 100644 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/CqlCompilerOptions.java +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/CqlCompilerOptions.java @@ -29,7 +29,7 @@ public enum Options { private boolean enableCqlOnly = false; private String compatibilityLevel = "1.5"; private CqlCompilerException.ErrorSeverity errorLevel = CqlCompilerException.ErrorSeverity.Info; - private LibraryBuilder.SignatureLevel signatureLevel = LibraryBuilder.SignatureLevel.None; + private LibraryBuilder.SignatureLevel signatureLevel = LibraryBuilder.SignatureLevel.Overloads; private boolean analyzeDataRequirements = false; private boolean collapseDataRequirements = false; diff --git a/Src/java/cql-to-elm/src/test/resources/org/cqframework/cql/cql2elm/options.json b/Src/java/cql-to-elm/src/test/resources/org/cqframework/cql/cql2elm/options.json index 1834225ea..83c1d815a 100644 --- a/Src/java/cql-to-elm/src/test/resources/org/cqframework/cql/cql2elm/options.json +++ b/Src/java/cql-to-elm/src/test/resources/org/cqframework/cql/cql2elm/options.json @@ -1 +1 @@ -{"options":["EnableAnnotations","EnableLocators","DisableListDemotion","DisableListPromotion"],"formats":[ "XML"],"validateUnits":true,"verifyOnly":false,"errorLevel":"Info","signatureLevel":"None"} \ No newline at end of file +{"options":["EnableAnnotations","EnableLocators","DisableListDemotion","DisableListPromotion"],"formats":[ "XML"],"validateUnits":true,"verifyOnly":false,"errorLevel":"Info","signatureLevel":"Overloads"} \ No newline at end of file diff --git a/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/TestFHIRHelpers.java b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/TestFHIRHelpers.java index ed88db13f..0dc4fe0c0 100644 --- a/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/TestFHIRHelpers.java +++ b/Src/java/engine-fhir/src/test/java/org/opencds/cqf/cql/engine/fhir/data/TestFHIRHelpers.java @@ -18,35 +18,32 @@ class TestFHIRHelpers extends FhirExecutionTestBase { @Test - void testWithUnambiguousCompilerOptions() { - // Test with non-ambiguous compiler options. Should pass. + void testWithAmbiguousCompilerOptions() { + // This tests the behavior of the engine when the compiler + // options are set to allow ambiguous overloads + // It's expected that the engine will throw an exception + // + // If we update the FHIRHelpers content to not have ambiguous overloads + // the results of this test will change var compilerOptions = CqlCompilerOptions.defaultOptions(); - compilerOptions.setSignatureLevel(LibraryBuilder.SignatureLevel.Overloads); + compilerOptions.setSignatureLevel(LibraryBuilder.SignatureLevel.None); var modelManager = new ModelManager(); var libraryManager = new LibraryManager(modelManager, compilerOptions); libraryManager.getLibrarySourceLoader().clearProviders(); libraryManager.getLibrarySourceLoader().registerProvider(new FhirLibrarySourceProvider()); libraryManager.getLibrarySourceLoader().registerProvider(new TestLibrarySourceProvider()); - var engine = new CqlEngine(new Environment(libraryManager)); - engine.getEnvironment().registerDataProvider("http://hl7.org/fhir", r4Provider); + var badOptionsEngine = new CqlEngine(new Environment(libraryManager)); + badOptionsEngine.getEnvironment().registerDataProvider("http://hl7.org/fhir", r4Provider); - runTest(engine); + var identifier = library.getIdentifier(); + assertThrows(CqlException.class, () -> badOptionsEngine.evaluate(identifier)); } @Test - void standardCompilerOptions() { - // Test with standard compiler options. Should throw an Exception as of the - // time this test is written because the default compiler options produce - // ambiguous ELM output. This test is intended to fail, and if we change the - // compiler options to be non-ambiguous, this test should be updated to expect - // a different (presumably passing) result. + void testFhirHelpers() { var engine = getEngine(); engine.getEnvironment().registerDataProvider("http://hl7.org/fhir", r4Provider); - assertThrows(CqlException.class, () -> runTest(engine)); - } - - void runTest(CqlEngine engine) { var results = engine.evaluate(library.getIdentifier()); // Primitives