Skip to content

Commit

Permalink
CQF-Tooling Update and Test coverage increase (#516)
Browse files Browse the repository at this point in the history
* KALM-110: Increase test Coverage and updated CQF-Tooling
Fixed QdmToQICore tool by updating getPageContent and added test to verify HTML pages creation.

* KALM-110: Increase test Coverage and updated CQF-Tooling
Fixed QdmToQICore tool by updating getPageContent and added test to verify HTML pages creation.

* KALM-110: Increase test Coverage and updated CQF-Tooling
Updated test to match other tests

* KALM-110: Increase test Coverage and updated CQF-Tooling
Added example commands for multiple tools in Main (Updated Tech doc)
Created Test class for BundleToResource tool (Bundle decomposition). Input Data also added (bundle of libraryevaluationtest-bundle.json)

* KALM-110: Increase test Coverage and updated CQF-Tooling
Added static final variable for BundleToResource args parameters

* KALM-110: Increase test Coverage and updated CQF-Tooling
Added test for BundleToTransaction tooling.
Updated tech docs with example command
  • Loading branch information
ddieppois authored Feb 28, 2024
1 parent 2b04b72 commit 241bd02
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 5 deletions.
12 changes: 9 additions & 3 deletions tooling-cli/src/main/java/org/opencds/cqf/tooling/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
This project provides tooling for the following use cases:
- QDM to QiCore mapping generation
- command: mvn exec:java -Dexec.args="[-QdmToQiCore] (output directory path)"
- Example: mvn exec:java -Dexec.args="-QdmToQiCore /Users/christopherschuler/Documents/workspace/QdmToQiCoreFiles"
- Example: mvn -Dexec.mainClass="org.opencds.cqf.tooling.cli.Main" exec:java -Dexec.args="-QdmToQiCore /Users/daviddieppois/Documents/git/cqf-tooling/tooling-cli/results"
- This tooling generates HTML pages from http://wiki.hl7.org/index.php?title=Harmonization_of_Health_Quality_Information_models
for the QiCore implementation guide
- QiCore QUICK page generation
- command: mvn exec:java -Dexec.args="[-QiCoreQUICK] [path to QiCore output directory] (output directory path)"
- /Users/christopherschuler/Documents/workspace/harmoniq/repos/qi-core/output
- Example: mvn -Dexec.mainClass="org.opencds.cqf.tooling.cli.Main" exec:java -Dexec.args="-QiCoreQUICK /Users/daviddieppois/Documents/git/cqf-tooling/tooling-cli/results"
- VSAC Excel spreadsheet to FHIR ValueSet resource conversion
- command: mvn exec:java -Dexec.args="[-VsacXlsxToValueSet] [-pathtospreadsheet | -pts] (-outputpath | -op) (-encoding | -e) (-metasheetnum | -msn) (-metanamerow | -mnr) (-metaoidrow | -mor) (-metastewardrow | -msr) (-codesheetnum | -csn) (-codelistrow | -clr) (-codecol | -cc) (-descriptioncol | -dc) (-systemnamecol | -snc) (-versioncol | -vc) (-systemoidcol | -soc)"
Expand All @@ -36,7 +37,8 @@
- This operation is configurable and can be used with spreadsheets that do not conform to VSAC export format (although we suggest using the -XlsxToValueSet operation as it is much more flexible and configurable).
- TemplateValuesetGenerator - WAS: XLSX Opioid ValueSet terminology generator
- command: mvn exec:java -Dexec.args="[-TemplateValuesetGenerator] [-pathtospreadsheet=<path> | -pts] (-outputpath | -op) (-encoding | -e) (-outputprefix | -opp) (-outputversion | -opv)"
- command: mvn exec:java -Dexec.args="[-TemplateToValueSetGenerator] [-pathtospreadsheet=<path> | -pts] (-outputpath | -op) (-encoding | -e) (-outputprefix | -opp) (-outputversion | -opv)"
- Example: mvn -Dexec.mainClass="org.opencds.cqf.tooling.cli.Main" exec:java -Dexec.args="-TemplateToValueSetGenerator -pts=/Users/daviddieppois/Documents/git/cqf-tooling/tooling-cli/src/main/resources/CDC_Opioid_Terminology_Master.xlsx -op=/Users/daviddieppois/Documents/git/cqf-tooling/tooling-cli/r4"
- This tooling converts the CDC Opioid XLSX spreadsheet from MD Partners to valuesets.
- Outputversion, if not specified, defaults to R4.
Expand All @@ -50,6 +52,7 @@
- CQL to FHIR Library conversion
- command: mvn exec:java -Dexec.args="[-CqlToSTU3Library|-CqlToR4Library] [-pathtolibrarydirectory | -ptld] (-encoding | -e) (-outputpath | -op)"
- Example: java -Dexec.args="-CqlToR4Library -ptld=/Users/christopherschuler/Src/cqframework/opioid-cds-r4/pages/cql/ -op=/Users/christopherschuler/Src/cqframework/opioid-cds-r4/resources"
- 2nd Example: mvn -Dexec.mainClass="org.opencds.cqf.tooling.cli.Main" -Dexec.args="-CqlToR4Library -ptld=/Users/daviddieppois/Documents/git/cqf-tooling/tooling-cli/output -op=/Users/daviddieppois/Documents/git/cqf-tooling/tooling-cli/r4"
- This tooling converts CQL libraries to FHIR Library resources
- The following elements will be populated in the FHIR Library resource:
- id (auto-generated)
Expand All @@ -67,6 +70,7 @@
- CQL to FHIR Measure conversion
- command: mvn exec:java -Dexec.args="[-CqlToMeasure] [path to CQL library] (id) (encoding) (contentType encoding) (-ip=initial population criteria) {-nX=numerator X criteria} {-dX=denominator X criteria} {sX=stratifier X criteria} (org.opencds.cqf.qdm.output directory path)"
- Example: mvn -Dexec.mainClass="org.opencds.cqf.tooling.cli.Main" -Dexec.args="-CqlToMeasure -ptld=/Users/daviddieppois/Documents/git/cqf-tooling/tooling-cli/output/Antibiotic.cql"
- NOTE: The 'X' for the numerator, denominator and stratifier params MUST be an Integer value
- If the numerator, denominator and stratifier params are not provided, the following criteria naming conventions MUST be followed:
- initial population: "Initial Population"
Expand All @@ -87,6 +91,7 @@
- Refresh Measure(s)
- command: mvn exec:java -Dexec.args="[-RefreshStu3Measure|RefreshR4Measure] [-ptm| pathToMeasures] [-ptl|pathToLibraries] (-e|encoding) (-o|-output) (-ss|-stamp)"
- Example: mvn -Dexec.mainClass="org.opencds.cqf.tooling.cli.Main" -Dexec.args="-RefreshStu3Measure -ptm=/Users/daviddieppois/Documents/git/cqf-tooling/tooling/src/test/resources/org/opencds/cqf/tooling/stu3/input/resources/measure -ptl=/Users/daviddieppois/Documents/git/cqf-tooling/tooling/src/test/resources/org/opencds/cqf/tooling/stu3/input/resources/library -o=/Users/daviddieppois/Documents/git/cqf-tooling/tooling-cli/output"
- Refresh Library
- command: mvn exec:java -Dexec.args"-RefreshLibrary -ini -fv|fhir-version -lp|libraryPath (-ss|-stamp)
Expand Down Expand Up @@ -119,12 +124,13 @@
- Bundle decomposition
- mvn exec:java -Dexec.args="[-BundleToResources] [Bundle file path] (output encoding)
- Example: mvn exec:java -Dexec.args="-BundleToResources /Users/christopherschuler/Documents/workspace/Bundles/bundle-1.json json /Users/christopherschuler/Documents/workspace/resources"
- Example: mvn -Dexec.mainClass="org.opencds.cqf.tooling.cli.Main" exec:java -Dexec.args="-BundleToResources -p=/Users/daviddieppois/Documents/git/cqf-tooling/tooling-cli/src/main/resources/libraryevaluationtest-bundle.json -e=json -op=/Users/daviddieppois/Documents/git/cqf-tooling/tooling-cli/output"
- This tooling decomposes a Bundle entry into separate resource files
- Accepts Bundles with .json or .xml extensions
- Bundle transaction - Converts a collection bundle to a transaction bundle
- mvn exec:java -Dexec.args="-MakeTransaction [Bundle file path] (output encoding)
- Example: mvn -Dexec.mainClass="org.opencds.cqf.tooling.cli.Main" exec:java -Dexec.args="-MakeTransaction -p=/Users/daviddieppois/Documents/git/cqf-tooling/tooling/src/main/resources/libraryevaluationtest-bundle.json -e=json -op=/Users/daviddieppois/Documents/git/cqf-tooling/tooling-cli/bundleTransaction"
- This tooling converts a collection bundle to a transaction bundle
- Accepts bundles with .json or .xml extensions
Expand Down
19 changes: 17 additions & 2 deletions tooling/src/main/java/org/opencds/cqf/tooling/qdm/QdmToQiCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.net.HttpURLConnection;

import org.apache.commons.lang3.StringUtils;
import org.opencds.cqf.tooling.Operation;
Expand Down Expand Up @@ -191,12 +192,26 @@ private String getCleanContent(String content) {

private String getPageContent(URL url) throws IOException {
StringBuilder content = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setInstanceFollowRedirects(true);

int status = conn.getResponseCode();
if (status != HttpURLConnection.HTTP_OK) {
if (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM || status == HttpURLConnection.HTTP_SEE_OTHER || status == 307 || status == 308) {
String newUrl = conn.getHeaderField("Location");
return getPageContent(new URL(newUrl));
} else {
throw new IOException("Unexpected response code: " + status);
}
}

try (BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
String line;
while((line = reader.readLine()) != null) {
while ((line = reader.readLine()) != null) {
content.append(line).append(System.lineSeparator());
}
}
return content.toString();
}

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.opencds.cqf.tooling.operation;

import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.File;
import java.util.HashSet;
import java.util.Set;

public class BundleToResourcesTest {
private final BundleToResources bundleToResources = new BundleToResources();
private final String PATH_ARGUMENT = "-p=";
private final String OUTPUT_PATH_ARGUMENT = "-op=";
private final String ENCODING_ARGUMENT = "-e=";

@Test
public void testExecute_BundleDecomposition() {
String projectPath = System.getProperty("user.dir");

String relativeJsonPath = "src/main/resources/libraryevaluationtest-bundle.json";
String jsonFilePath = projectPath + File.separator + relativeJsonPath;

String relativePath = "tooling-cli/bundleResourcesResults";

String[] args = new String[4];
args[0] = "-BundleToResources";
args[1] = PATH_ARGUMENT + jsonFilePath;
args[2] = ENCODING_ARGUMENT+ "json";
args[3] = OUTPUT_PATH_ARGUMENT + projectPath + File.separator + relativePath;
bundleToResources.execute(args);

File resultDir = new File(projectPath + File.separator + relativePath);

Assert.assertTrue(resultDir.exists() && resultDir.isDirectory(), "Result directory does not exist.");

// Expected file names
Set<String> expectedFiles = new HashSet<>();
expectedFiles.add("Library-LibraryEvaluationTest.json");
expectedFiles.add("Library-LibraryEvaluationTestConcepts.json");
expectedFiles.add("Library-LibraryEvaluationTestDependency.json");
expectedFiles.add("Questionnaire-libraryevaluationtest.json");
expectedFiles.add("ValueSet-condition-problem-list-category.json");

File[] actualFiles = resultDir.listFiles((dir, name) -> name.endsWith(".json"));
Assert.assertNotNull(actualFiles, "Bundle resource folder should not be null.");

// Check if all expected files are present
for (String expectedFile : expectedFiles) {
boolean found = false;
for (File file : actualFiles) {
if (file.getName().equals(expectedFile)) {
found = true;
break;
}
}
Assert.assertTrue(found, "Expected file not found: " + expectedFile);
}

Assert.assertEquals(actualFiles.length, expectedFiles.size(), "Expected " + expectedFiles.size() + " resources files, but found " + actualFiles.length + ".");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.opencds.cqf.tooling.operation;

import junit.framework.TestCase;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.File;
import java.util.HashSet;
import java.util.Set;

public class BundleToTransactionOperationTest extends TestCase {
private final BundleToTransactionOperation bundleToTransactionOperation = new BundleToTransactionOperation();
private final String PATH_ARGUMENT = "-p=";
private final String OUTPUT_PATH_ARGUMENT = "-op=";
private final String ENCODING_ARGUMENT = "-e=";

@Test
public void testExecute_BundleDecomposition() {
String projectPath = System.getProperty("user.dir");

String relativeJsonPath = "src/main/resources/libraryevaluationtest-bundle.json";
String jsonFilePath = projectPath + File.separator + relativeJsonPath;

String relativePath = "tooling-cli/bundleTransactionResults";

String[] args = new String[4];
args[0] = "-MakeTransaction";
args[1] = PATH_ARGUMENT + jsonFilePath;
args[2] = ENCODING_ARGUMENT + "json";
args[3] = OUTPUT_PATH_ARGUMENT + projectPath + File.separator + relativePath;
bundleToTransactionOperation.execute(args);

File resultDir = new File(projectPath + File.separator + relativePath);

Assert.assertTrue(resultDir.exists() && resultDir.isDirectory(), "Result directory does not exist.");

String expectedFile = "Bundle-libraryevaluationtest-bundle.json";

File[] actualFiles = resultDir.listFiles((dir, name) -> name.endsWith(".json"));
Assert.assertNotNull(actualFiles, "Bundle resource folder should not be null.");

boolean found = false;
for (File file : actualFiles) {
if (file.getName().equals(expectedFile)) {
found = true;
break;
}
}
Assert.assertTrue(found, "Expected file not found: " + expectedFile);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.opencds.cqf.tooling.qdm;

import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.File;

public class QdmToQiCoreTest {

private final QdmToQiCore qdmToQiCore = new QdmToQiCore();

@Test
public void testExecute_HtmlFilesCreated() {
String projectPath = System.getProperty("user.dir");
String relativePath = "tooling-cli/results";

String[] args = new String[2];
args[0] = "-QdmToQiCore";
args[1] = projectPath + File.separator + relativePath;
qdmToQiCore.execute(args);

File resultDir = new File(args[1]);

Assert.assertTrue(resultDir.exists() && resultDir.isDirectory(), "Result directory does not exist.");

File[] htmlFiles = resultDir.listFiles((dir, name) -> name.endsWith(".html"));

Assert.assertNotNull(htmlFiles, "HTML files array should not be null.");

Assert.assertEquals(htmlFiles.length, 21, "Expected 21 HTML files, but found " + htmlFiles.length + ".");
}

}

0 comments on commit 241bd02

Please sign in to comment.