From 96e6b8890bc017d6926f43650f8c33b672a06083 Mon Sep 17 00:00:00 2001 From: Holly Wu Date: Mon, 5 Aug 2024 16:08:14 -0700 Subject: [PATCH 1/9] Support remote repositories --- .../cqf/cql/ls/server/command/CqlCommand.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/CqlCommand.java b/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/CqlCommand.java index b14077f..06e9832 100644 --- a/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/CqlCommand.java +++ b/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/CqlCommand.java @@ -2,11 +2,14 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; + import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; + +import ca.uhn.fhir.rest.client.apache.ApacheHttpClient; import org.apache.commons.lang3.tuple.Pair; import org.cqframework.cql.cql2elm.CqlTranslatorOptions; import org.cqframework.cql.cql2elm.CqlTranslatorOptionsMapper; @@ -35,6 +38,7 @@ import org.opencds.cqf.fhir.cql.engine.terminology.TerminologySettings.VALUESET_MEMBERSHIP_MODE; import org.opencds.cqf.fhir.cql.engine.terminology.TerminologySettings.VALUESET_PRE_EXPANSION_MODE; import org.opencds.cqf.fhir.utility.repository.ProxyRepository; +import org.opencds.cqf.fhir.utility.repository.RestRepository; import org.opencds.cqf.fhir.utility.repository.ig.IgRepository; import org.slf4j.LoggerFactory; import picocli.CommandLine.ArgGroup; @@ -125,10 +129,9 @@ static class ParameterParameter { } } - private static class Logger implements ILoggingService { - - private final org.slf4j.Logger log = LoggerFactory.getLogger(Logger.class); + private static final org.slf4j.Logger log = LoggerFactory.getLogger(Logger.class); + private static class Logger implements ILoggingService { @Override public void logMessage(String s) { log.warn(s); @@ -198,15 +201,9 @@ public Integer call() throws Exception { for (LibraryParameter library : libraries) { var libraryPath = Paths.get(Uris.parseOrNull(library.libraryUrl)); - var modelPath = library.model != null - ? Paths.get(Uris.parseOrNull(library.model.modelUrl)) - : null; - - var terminologyPath = library.terminologyUrl != null - ? Paths.get(Uris.parseOrNull(library.terminologyUrl)) - : null; + var modelUrl = library.model != null ? library.model.modelUrl : null; - var repository = createRepository(fhirContext, terminologyPath, modelPath); + var repository = createRepository(fhirContext, library.terminologyUrl, modelUrl); var engine = Engines.forRepositoryAndSettings( evaluationSettings, repository, null, new NpmProcessor(igContext), true); @@ -234,22 +231,24 @@ public Integer call() throws Exception { return 0; } - private Repository createRepository(FhirContext fhirContext, Path terminologyPath, Path modelPath) { + private Repository createRepository(FhirContext fhirContext, String terminologyUrl, String modelUrl) { Repository data = null; Repository terminology = null; - if (terminologyPath == null && modelPath == null) { + if (terminologyUrl == null && modelUrl == null) { return new NoOpRepository(fhirContext); } - if (modelPath != null) { - data = new IgRepository(fhirContext, modelPath); - } else { + if(modelUrl == null) { data = new NoOpRepository(fhirContext); + } else if(modelUrl.startsWith("file:///")) { + data = new IgRepository(fhirContext, Paths.get(Uris.parseOrNull(modelUrl))); + } else if(modelUrl.startsWith("http://") || modelUrl.startsWith(("https://"))) { + data = new RestRepository(fhirContext.newRestfulGenericClient(modelUrl)); } - if (terminologyPath != null) { - terminology = new IgRepository(fhirContext, terminologyPath); + if (terminologyUrl != null) { + terminology = new IgRepository(fhirContext, Paths.get(Uris.parseOrNull(terminologyUrl))); } else { terminology = new NoOpRepository(fhirContext); } From 2aa8726ce7e244ee59148bf3d5dade1044aed267 Mon Sep 17 00:00:00 2001 From: Holly Wu Date: Tue, 6 Aug 2024 22:29:00 -0700 Subject: [PATCH 2/9] Add DebugCql contribution test --- .../cqf/cql/ls/server/command/CqlCommand.java | 12 ++-- .../cql/ls/server/command/CqlCommandTest.java | 12 ++++ .../DebugCqlCommandContributionTest.java | 60 +++++++++++++++++++ 3 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/CqlCommandTest.java create mode 100644 ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java diff --git a/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/CqlCommand.java b/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/CqlCommand.java index 06e9832..fce0cf2 100644 --- a/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/CqlCommand.java +++ b/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/CqlCommand.java @@ -2,14 +2,10 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; - -import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; - -import ca.uhn.fhir.rest.client.apache.ApacheHttpClient; import org.apache.commons.lang3.tuple.Pair; import org.cqframework.cql.cql2elm.CqlTranslatorOptions; import org.cqframework.cql.cql2elm.CqlTranslatorOptionsMapper; @@ -239,12 +235,14 @@ private Repository createRepository(FhirContext fhirContext, String terminologyU return new NoOpRepository(fhirContext); } - if(modelUrl == null) { + if (modelUrl == null) { data = new NoOpRepository(fhirContext); - } else if(modelUrl.startsWith("file:///")) { + } else if (modelUrl.startsWith("file:///")) { data = new IgRepository(fhirContext, Paths.get(Uris.parseOrNull(modelUrl))); - } else if(modelUrl.startsWith("http://") || modelUrl.startsWith(("https://"))) { + } else if (modelUrl.startsWith("http://") || modelUrl.startsWith(("https://"))) { data = new RestRepository(fhirContext.newRestfulGenericClient(modelUrl)); + } else { + data = new NoOpRepository(fhirContext); } if (terminologyUrl != null) { diff --git a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/CqlCommandTest.java b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/CqlCommandTest.java new file mode 100644 index 0000000..b5782b4 --- /dev/null +++ b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/CqlCommandTest.java @@ -0,0 +1,12 @@ +package org.opencds.cqf.cql.ls.server.command; + +import org.junit.jupiter.api.Test; + +class CqlCommandTest { + private static DebugCqlCommandContribution contribution; + + @Test + void executeCommand() { + + } +} diff --git a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java new file mode 100644 index 0000000..f0f4ea7 --- /dev/null +++ b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java @@ -0,0 +1,60 @@ +package org.opencds.cqf.cql.ls.server.command; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.google.gson.JsonParser; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.stream.Collectors; + +import org.eclipse.lsp4j.ExecuteCommandParams; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.opencds.cqf.cql.ls.core.ContentService; +import org.opencds.cqf.cql.ls.server.manager.CompilerOptionsManager; +import org.opencds.cqf.cql.ls.server.manager.CqlCompilationManager; +import org.opencds.cqf.cql.ls.server.manager.IgContextManager; +import org.opencds.cqf.cql.ls.server.service.TestContentService; + +class DebugCqlCommandContributionTest { + + private static DebugCqlCommandContribution contribution; + + @BeforeAll + static void beforeAll() { + ContentService cs = new TestContentService(); + contribution = new DebugCqlCommandContribution(new IgContextManager((cs))); + } + + @Test + void getCommands() { + assertEquals(1, contribution.getCommands().size()); + assertEquals( + "org.opencds.cqf.cql.ls.plugin.debug.startDebugSession", + contribution.getCommands().toArray()[0]); + } + + @Test + void executeCommand() { + ExecuteCommandParams params = new ExecuteCommandParams(); + System.out.println(System.getProperty("user.dir")); + params.setCommand("org.opencds.cqf.cql.ls.plugin.debug.startDebugSession"); + params.setArguments(Arrays.asList( + "cql", + "-fv=R4", + "-m=FHIR", + "-mu=/org/opencds/cqf/cql/ls/server/One.cql", + "-ln=One", + "-lu=file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/", + "-t=file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/" + ).stream().map(str -> "\"" + str + "\"").map(JsonParser::parseString).collect(Collectors.toList())); + contribution.executeCommand(params).thenAccept(result -> { + assertEquals("One=1", result.toString()); + }); + } +} From c615fc795c91fb108530a9663736bf152227233c Mon Sep 17 00:00:00 2001 From: Holly Wu Date: Wed, 7 Aug 2024 21:14:34 -0700 Subject: [PATCH 3/9] Normalize path for Windows; fix assertion not running due to unawaited future --- .../DebugCqlCommandContributionTest.java | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java index f0f4ea7..8aba7e2 100644 --- a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java +++ b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java @@ -1,10 +1,10 @@ package org.opencds.cqf.cql.ls.server.command; -import static org.junit.jupiter.api.Assertions.assertEquals; - import com.google.gson.JsonParser; +import java.io.File; import java.io.IOException; +import java.net.URI; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; @@ -12,6 +12,7 @@ import java.util.Collections; import java.util.stream.Collectors; +import org.apache.commons.lang3.SystemUtils; import org.eclipse.lsp4j.ExecuteCommandParams; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -21,8 +22,12 @@ import org.opencds.cqf.cql.ls.server.manager.IgContextManager; import org.opencds.cqf.cql.ls.server.service.TestContentService; +import static org.junit.jupiter.api.Assertions.*; + class DebugCqlCommandContributionTest { + private static final String FILE_UNC_PREFIX = "file:///"; + private static DebugCqlCommandContribution contribution; @BeforeAll @@ -42,19 +47,33 @@ void getCommands() { @Test void executeCommand() { ExecuteCommandParams params = new ExecuteCommandParams(); - System.out.println(System.getProperty("user.dir")); + + String libraryPath = normalizePath("file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); + params.setCommand("org.opencds.cqf.cql.ls.plugin.debug.startDebugSession"); params.setArguments(Arrays.asList( "cql", "-fv=R4", "-m=FHIR", - "-mu=/org/opencds/cqf/cql/ls/server/One.cql", "-ln=One", - "-lu=file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/", - "-t=file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/" + "-lu=" + libraryPath, + "-t=" + libraryPath ).stream().map(str -> "\"" + str + "\"").map(JsonParser::parseString).collect(Collectors.toList())); - contribution.executeCommand(params).thenAccept(result -> { - assertEquals("One=1", result.toString()); - }); + Object result = contribution.executeCommand(params).join(); + assertInstanceOf(String.class, result); + assertTrue(((String) result).trim().endsWith("One=1")); + } + + private static String normalizePath(String path) { + if(SystemUtils.IS_OS_WINDOWS && path.startsWith(FILE_UNC_PREFIX)) { + try { + URI uri = new URI(path); + return new File(uri.getSchemeSpecificPart()).toURI().getRawPath(); + } catch(Exception e) { + return path; + } + } + + return path; } } From 0b06e2b79247c18586d0855fcbb085d7b6a54cce Mon Sep 17 00:00:00 2001 From: Holly Wu Date: Thu, 8 Aug 2024 15:46:16 -0700 Subject: [PATCH 4/9] More tests, hopefully more coverage --- .../DebugCqlCommandContributionTest.java | 85 ++++++++++++++++++- .../org/opencds/cqf/cql/ls/server/One.xml | 6 +- 2 files changed, 87 insertions(+), 4 deletions(-) diff --git a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java index 8aba7e2..fde346f 100644 --- a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java +++ b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java @@ -45,7 +45,7 @@ void getCommands() { } @Test - void executeCommand() { + void withOnlyLibrary() { ExecuteCommandParams params = new ExecuteCommandParams(); String libraryPath = normalizePath("file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); @@ -56,6 +56,47 @@ void executeCommand() { "-fv=R4", "-m=FHIR", "-ln=One", + "-lu=" + libraryPath + ).stream().map(str -> "\"" + str + "\"").map(JsonParser::parseString).collect(Collectors.toList())); + Object result = contribution.executeCommand(params).join(); + assertInstanceOf(String.class, result); + assertTrue(((String) result).trim().endsWith("One=1")); + } + + @Test + void withTerminology() { + ExecuteCommandParams params = new ExecuteCommandParams(); + + String libraryPath = normalizePath("file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); + + params.setCommand("org.opencds.cqf.cql.ls.plugin.debug.startDebugSession"); + params.setArguments(Arrays.asList( + "cql", + "-fv=R4", + "-m=FHIR", + "-ln=One", + "-lu=" + libraryPath, + "-t=" + libraryPath + ).stream().map(str -> "\"" + str + "\"").map(JsonParser::parseString).collect(Collectors.toList())); + Object result = contribution.executeCommand(params).join(); + assertInstanceOf(String.class, result); + assertTrue(((String) result).trim().endsWith("One=1")); + } + + @Test + void withFileModel() { + ExecuteCommandParams params = new ExecuteCommandParams(); + + String modelPath = normalizePath("file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); + String libraryPath = normalizePath("file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); + + params.setCommand("org.opencds.cqf.cql.ls.plugin.debug.startDebugSession"); + params.setArguments(Arrays.asList( + "cql", + "-fv=R4", + "-m=FHIR", + "-mu=" + modelPath, + "-ln=One", "-lu=" + libraryPath, "-t=" + libraryPath ).stream().map(str -> "\"" + str + "\"").map(JsonParser::parseString).collect(Collectors.toList())); @@ -64,6 +105,48 @@ void executeCommand() { assertTrue(((String) result).trim().endsWith("One=1")); } + @Test + void withRemoteModel() { + ExecuteCommandParams params = new ExecuteCommandParams(); + + String modelPath = "http://localhost:8000"; + String libraryPath = normalizePath("file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); + + params.setCommand("org.opencds.cqf.cql.ls.plugin.debug.startDebugSession"); + params.setArguments(Arrays.asList( + "cql", + "-fv=R4", + "-m=FHIR", + "-mu=" + modelPath, + "-ln=One", + "-lu=" + libraryPath, + "-t=" + libraryPath + ).stream().map(str -> "\"" + str + "\"").map(JsonParser::parseString).collect(Collectors.toList())); + Object result = contribution.executeCommand(params).join(); + assertInstanceOf(String.class, result); + assertTrue(((String) result).trim().endsWith("One=1")); + } + + @Test + void withRootDir() { + ExecuteCommandParams params = new ExecuteCommandParams(); + + String libraryPath = normalizePath("file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); + + params.setCommand("org.opencds.cqf.cql.ls.plugin.debug.startDebugSession"); + params.setArguments(Arrays.asList( + "cql", + "-fv=R4", + "-m=FHIR", + "--root-dir=" + libraryPath, + "-ln=One", + "-lu=" + libraryPath + ).stream().map(str -> "\"" + str + "\"").map(JsonParser::parseString).collect(Collectors.toList())); + Object result = contribution.executeCommand(params).join(); + assertInstanceOf(String.class, result); + assertTrue(((String) result).trim().endsWith("One=1")); + } + private static String normalizePath(String path) { if(SystemUtils.IS_OS_WINDOWS && path.startsWith(FILE_UNC_PREFIX)) { try { diff --git a/ls/server/src/test/resources/org/opencds/cqf/cql/ls/server/One.xml b/ls/server/src/test/resources/org/opencds/cqf/cql/ls/server/One.xml index c5fe2a4..7bf6ecd 100644 --- a/ls/server/src/test/resources/org/opencds/cqf/cql/ls/server/One.xml +++ b/ls/server/src/test/resources/org/opencds/cqf/cql/ls/server/One.xml @@ -1,12 +1,12 @@ - + library One - + @@ -22,4 +22,4 @@ - \ No newline at end of file + \ No newline at end of file From fcec5906535f359cbc9cb2ce398b939a33a1c338 Mon Sep 17 00:00:00 2001 From: Holly Wu Date: Thu, 8 Aug 2024 17:35:14 -0700 Subject: [PATCH 5/9] Remove remote test --- .../DebugCqlCommandContributionTest.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java index fde346f..62e7281 100644 --- a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java +++ b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java @@ -105,27 +105,27 @@ void withFileModel() { assertTrue(((String) result).trim().endsWith("One=1")); } - @Test - void withRemoteModel() { - ExecuteCommandParams params = new ExecuteCommandParams(); - - String modelPath = "http://localhost:8000"; - String libraryPath = normalizePath("file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); - - params.setCommand("org.opencds.cqf.cql.ls.plugin.debug.startDebugSession"); - params.setArguments(Arrays.asList( - "cql", - "-fv=R4", - "-m=FHIR", - "-mu=" + modelPath, - "-ln=One", - "-lu=" + libraryPath, - "-t=" + libraryPath - ).stream().map(str -> "\"" + str + "\"").map(JsonParser::parseString).collect(Collectors.toList())); - Object result = contribution.executeCommand(params).join(); - assertInstanceOf(String.class, result); - assertTrue(((String) result).trim().endsWith("One=1")); - } +// @Test +// void withRemoteModel() { +// ExecuteCommandParams params = new ExecuteCommandParams(); +// +// String modelPath = "http://localhost:8000"; +// String libraryPath = normalizePath("file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); +// +// params.setCommand("org.opencds.cqf.cql.ls.plugin.debug.startDebugSession"); +// params.setArguments(Arrays.asList( +// "cql", +// "-fv=R4", +// "-m=FHIR", +// "-mu=" + modelPath, +// "-ln=One", +// "-lu=" + libraryPath, +// "-t=" + libraryPath +// ).stream().map(str -> "\"" + str + "\"").map(JsonParser::parseString).collect(Collectors.toList())); +// Object result = contribution.executeCommand(params).join(); +// assertInstanceOf(String.class, result); +// assertTrue(((String) result).trim().endsWith("One=1")); +// } @Test void withRootDir() { From 48fe0d1c4e5352fa56d410b8c125aa6fa325b6ab Mon Sep 17 00:00:00 2001 From: Holly Wu Date: Thu, 8 Aug 2024 18:21:13 -0700 Subject: [PATCH 6/9] Run spotless --- .../cql/ls/server/command/CqlCommandTest.java | 4 +- .../DebugCqlCommandContributionTest.java | 132 ++++++++---------- 2 files changed, 63 insertions(+), 73 deletions(-) diff --git a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/CqlCommandTest.java b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/CqlCommandTest.java index b5782b4..3ca5b73 100644 --- a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/CqlCommandTest.java +++ b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/CqlCommandTest.java @@ -6,7 +6,5 @@ class CqlCommandTest { private static DebugCqlCommandContribution contribution; @Test - void executeCommand() { - - } + void executeCommand() {} } diff --git a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java index 62e7281..b2ed068 100644 --- a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java +++ b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java @@ -1,29 +1,20 @@ package org.opencds.cqf.cql.ls.server.command; -import com.google.gson.JsonParser; +import static org.junit.jupiter.api.Assertions.*; +import com.google.gson.JsonParser; import java.io.File; -import java.io.IOException; import java.net.URI; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.stream.Collectors; - import org.apache.commons.lang3.SystemUtils; import org.eclipse.lsp4j.ExecuteCommandParams; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.opencds.cqf.cql.ls.core.ContentService; -import org.opencds.cqf.cql.ls.server.manager.CompilerOptionsManager; -import org.opencds.cqf.cql.ls.server.manager.CqlCompilationManager; import org.opencds.cqf.cql.ls.server.manager.IgContextManager; import org.opencds.cqf.cql.ls.server.service.TestContentService; -import static org.junit.jupiter.api.Assertions.*; - class DebugCqlCommandContributionTest { private static final String FILE_UNC_PREFIX = "file:///"; @@ -48,16 +39,14 @@ void getCommands() { void withOnlyLibrary() { ExecuteCommandParams params = new ExecuteCommandParams(); - String libraryPath = normalizePath("file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); + String libraryPath = normalizePath( + "file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); params.setCommand("org.opencds.cqf.cql.ls.plugin.debug.startDebugSession"); - params.setArguments(Arrays.asList( - "cql", - "-fv=R4", - "-m=FHIR", - "-ln=One", - "-lu=" + libraryPath - ).stream().map(str -> "\"" + str + "\"").map(JsonParser::parseString).collect(Collectors.toList())); + params.setArguments(Arrays.asList("cql", "-fv=R4", "-m=FHIR", "-ln=One", "-lu=" + libraryPath).stream() + .map(str -> "\"" + str + "\"") + .map(JsonParser::parseString) + .collect(Collectors.toList())); Object result = contribution.executeCommand(params).join(); assertInstanceOf(String.class, result); assertTrue(((String) result).trim().endsWith("One=1")); @@ -67,17 +56,15 @@ void withOnlyLibrary() { void withTerminology() { ExecuteCommandParams params = new ExecuteCommandParams(); - String libraryPath = normalizePath("file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); + String libraryPath = normalizePath( + "file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); params.setCommand("org.opencds.cqf.cql.ls.plugin.debug.startDebugSession"); - params.setArguments(Arrays.asList( - "cql", - "-fv=R4", - "-m=FHIR", - "-ln=One", - "-lu=" + libraryPath, - "-t=" + libraryPath - ).stream().map(str -> "\"" + str + "\"").map(JsonParser::parseString).collect(Collectors.toList())); + params.setArguments( + Arrays.asList("cql", "-fv=R4", "-m=FHIR", "-ln=One", "-lu=" + libraryPath, "-t=" + libraryPath).stream() + .map(str -> "\"" + str + "\"") + .map(JsonParser::parseString) + .collect(Collectors.toList())); Object result = contribution.executeCommand(params).join(); assertInstanceOf(String.class, result); assertTrue(((String) result).trim().endsWith("One=1")); @@ -87,72 +74,77 @@ void withTerminology() { void withFileModel() { ExecuteCommandParams params = new ExecuteCommandParams(); - String modelPath = normalizePath("file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); - String libraryPath = normalizePath("file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); + String modelPath = normalizePath( + "file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); + String libraryPath = normalizePath( + "file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); params.setCommand("org.opencds.cqf.cql.ls.plugin.debug.startDebugSession"); params.setArguments(Arrays.asList( - "cql", - "-fv=R4", - "-m=FHIR", - "-mu=" + modelPath, - "-ln=One", - "-lu=" + libraryPath, - "-t=" + libraryPath - ).stream().map(str -> "\"" + str + "\"").map(JsonParser::parseString).collect(Collectors.toList())); + "cql", + "-fv=R4", + "-m=FHIR", + "-mu=" + modelPath, + "-ln=One", + "-lu=" + libraryPath, + "-t=" + libraryPath) + .stream() + .map(str -> "\"" + str + "\"") + .map(JsonParser::parseString) + .collect(Collectors.toList())); Object result = contribution.executeCommand(params).join(); assertInstanceOf(String.class, result); assertTrue(((String) result).trim().endsWith("One=1")); } -// @Test -// void withRemoteModel() { -// ExecuteCommandParams params = new ExecuteCommandParams(); -// -// String modelPath = "http://localhost:8000"; -// String libraryPath = normalizePath("file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); -// -// params.setCommand("org.opencds.cqf.cql.ls.plugin.debug.startDebugSession"); -// params.setArguments(Arrays.asList( -// "cql", -// "-fv=R4", -// "-m=FHIR", -// "-mu=" + modelPath, -// "-ln=One", -// "-lu=" + libraryPath, -// "-t=" + libraryPath -// ).stream().map(str -> "\"" + str + "\"").map(JsonParser::parseString).collect(Collectors.toList())); -// Object result = contribution.executeCommand(params).join(); -// assertInstanceOf(String.class, result); -// assertTrue(((String) result).trim().endsWith("One=1")); -// } + // @Test + // void withRemoteModel() { + // ExecuteCommandParams params = new ExecuteCommandParams(); + // + // String modelPath = "http://localhost:8000"; + // String libraryPath = normalizePath("file://" + System.getProperty("user.dir") + + // "/src/test/resources/org/opencds/cqf/cql/ls/server/"); + // + // params.setCommand("org.opencds.cqf.cql.ls.plugin.debug.startDebugSession"); + // params.setArguments(Arrays.asList( + // "cql", + // "-fv=R4", + // "-m=FHIR", + // "-mu=" + modelPath, + // "-ln=One", + // "-lu=" + libraryPath, + // "-t=" + libraryPath + // ).stream().map(str -> "\"" + str + "\"").map(JsonParser::parseString).collect(Collectors.toList())); + // Object result = contribution.executeCommand(params).join(); + // assertInstanceOf(String.class, result); + // assertTrue(((String) result).trim().endsWith("One=1")); + // } @Test void withRootDir() { ExecuteCommandParams params = new ExecuteCommandParams(); - String libraryPath = normalizePath("file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); + String libraryPath = normalizePath( + "file://" + System.getProperty("user.dir") + "/src/test/resources/org/opencds/cqf/cql/ls/server/"); params.setCommand("org.opencds.cqf.cql.ls.plugin.debug.startDebugSession"); - params.setArguments(Arrays.asList( - "cql", - "-fv=R4", - "-m=FHIR", - "--root-dir=" + libraryPath, - "-ln=One", - "-lu=" + libraryPath - ).stream().map(str -> "\"" + str + "\"").map(JsonParser::parseString).collect(Collectors.toList())); + params.setArguments( + Arrays.asList("cql", "-fv=R4", "-m=FHIR", "--root-dir=" + libraryPath, "-ln=One", "-lu=" + libraryPath) + .stream() + .map(str -> "\"" + str + "\"") + .map(JsonParser::parseString) + .collect(Collectors.toList())); Object result = contribution.executeCommand(params).join(); assertInstanceOf(String.class, result); assertTrue(((String) result).trim().endsWith("One=1")); } private static String normalizePath(String path) { - if(SystemUtils.IS_OS_WINDOWS && path.startsWith(FILE_UNC_PREFIX)) { + if (SystemUtils.IS_OS_WINDOWS && path.startsWith(FILE_UNC_PREFIX)) { try { URI uri = new URI(path); return new File(uri.getSchemeSpecificPart()).toURI().getRawPath(); - } catch(Exception e) { + } catch (Exception e) { return path; } } From 5e8cafde02f11518a1cb7ce27ada8693e17710b0 Mon Sep 17 00:00:00 2001 From: Joshua Reynolds <48231325+jreyno77@users.noreply.github.com> Date: Sat, 10 Aug 2024 02:13:26 -0600 Subject: [PATCH 7/9] CQL Command Expression Evaluation (#78) * WIP on master Wire up expression to the actual engine evaluation * Run spotless * Remove irrelevant tests * Restore test --------- Co-authored-by: Holly Wu --- .../opencds/cqf/cql/ls/server/command/CqlCommand.java | 5 +++-- .../cqf/cql/ls/server/command/CqlCommandTest.java | 10 ---------- 2 files changed, 3 insertions(+), 12 deletions(-) delete mode 100644 ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/CqlCommandTest.java diff --git a/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/CqlCommand.java b/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/CqlCommand.java index fce0cf2..c1531c5 100644 --- a/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/CqlCommand.java +++ b/ls/server/src/main/java/org/opencds/cqf/cql/ls/server/command/CqlCommand.java @@ -5,6 +5,7 @@ import java.nio.file.Paths; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.Callable; import org.apache.commons.lang3.tuple.Pair; import org.cqframework.cql.cql2elm.CqlTranslatorOptions; @@ -95,7 +96,7 @@ static class LibraryParameter { public List parameters; @Option(names = {"-e", "--expression"}) - public String[] expression; + public Set expression; @ArgGroup(multiplicity = "0..1", exclusive = false) public ContextParameter context; @@ -219,7 +220,7 @@ public Integer call() throws Exception { contextParameter = Pair.of(library.context.contextName, library.context.contextValue); } - EvaluationResult result = engine.evaluate(identifier, contextParameter); + EvaluationResult result = engine.evaluate(identifier, library.expression, contextParameter); writeResult(result); } diff --git a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/CqlCommandTest.java b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/CqlCommandTest.java deleted file mode 100644 index 3ca5b73..0000000 --- a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/CqlCommandTest.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.opencds.cqf.cql.ls.server.command; - -import org.junit.jupiter.api.Test; - -class CqlCommandTest { - private static DebugCqlCommandContribution contribution; - - @Test - void executeCommand() {} -} From 9b14fb0862805e13bdc4bde4c8a8879f0116dcf5 Mon Sep 17 00:00:00 2001 From: Holly Wu Date: Tue, 13 Aug 2024 11:31:17 -0700 Subject: [PATCH 8/9] Replace backslashes with forward slashes in Windows paths --- .../ls/server/command/DebugCqlCommandContributionTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java index b2ed068..c3dfc97 100644 --- a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java +++ b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java @@ -141,12 +141,14 @@ void withRootDir() { private static String normalizePath(String path) { if (SystemUtils.IS_OS_WINDOWS && path.startsWith(FILE_UNC_PREFIX)) { + String wPath = path; try { URI uri = new URI(path); - return new File(uri.getSchemeSpecificPart()).toURI().getRawPath(); + wPath = new File(uri.getSchemeSpecificPart()).toURI().getRawPath(); } catch (Exception e) { - return path; } + + return wPath.replace('\\', '/'); } return path; From befe92c5ea5b2eaeeb528b0371f17ccaff048185 Mon Sep 17 00:00:00 2001 From: Holly Wu Date: Tue, 13 Aug 2024 16:46:43 -0700 Subject: [PATCH 9/9] Forgot a return path --- .../cql/ls/server/command/DebugCqlCommandContributionTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java index c3dfc97..d4cb27e 100644 --- a/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java +++ b/ls/server/src/test/java/org/opencds/cqf/cql/ls/server/command/DebugCqlCommandContributionTest.java @@ -151,6 +151,6 @@ private static String normalizePath(String path) { return wPath.replace('\\', '/'); } - return path; + return path.replace('\\', '/'); } }