Skip to content

Commit

Permalink
Move some serialization-based tests out of cql-to-elm and into elm-jaxb
Browse files Browse the repository at this point in the history
  • Loading branch information
JPercival committed Dec 26, 2024
1 parent 1627ddf commit 3b912cd
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 6 deletions.
2 changes: 0 additions & 2 deletions Src/java/cql-to-elm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ dependencies {
testImplementation(project(":qdm"))
testImplementation(project(":ucum"))
testImplementation("com.tngtech.archunit:archunit:1.2.1")
testImplementation("org.xmlunit:xmlunit-assertj:2.10.0")
testImplementation("org.skyscreamer:jsonassert:1.5.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ static void setup() throws IOException {
of = new ObjectFactory();
}

public static Object[][] primeNumbers() {
public static Object[][] signatureLevels() {
return new Object[][] {
{SignatureLevel.None}, {SignatureLevel.Differing}, {SignatureLevel.Overloads}, {SignatureLevel.All}
};
}

@ParameterizedTest
@MethodSource("primeNumbers")
@MethodSource("signatureLevels")
void signatureLevels(SignatureLevel signatureLevel) throws IOException {
final ModelManager modelManager = new ModelManager();
final CqlTranslator translator = CqlTranslator.fromStream(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.cqframework.cql.cql2elm;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import org.cqframework.cql.cql2elm.CqlCompilerException.ErrorSeverity;
import org.cqframework.cql.cql2elm.LibraryBuilder.SignatureLevel;
import org.cqframework.cql.elm.utility.Visitors;
import org.hl7.elm.r1.Element;
import org.hl7.elm.r1.OperatorExpression;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

class CMS146SignatureTest {

// This is a count of the number of expected
// signatures for each SignatureLevel when CMS146v2_Test_CQM.cql
// is compiled.
private static Object[][] sigCounts() {
return new Object[][] {
{SignatureLevel.None, 0},
{SignatureLevel.Differing, 3},
{SignatureLevel.Overloads, 11},
{SignatureLevel.All, 34}
};
}

@ParameterizedTest
@MethodSource("sigCounts")
void cms146SignatureLevels(SignatureLevel signatureLevel, int expectedSignatures) throws IOException {
final File cms146 = getFile("CMS146v2_Test_CQM.cql");
final ModelManager modelManager = new ModelManager();
final CqlTranslator translator = CqlTranslator.fromFile(
cms146,
new LibraryManager(modelManager, new CqlCompilerOptions(ErrorSeverity.Warning, signatureLevel)));

var visitor = Visitors.from(
(Element elm, Void context) -> {
if (elm instanceof OperatorExpression fd) {
return fd.getSignature().isEmpty() ? 0 : 1;
} else {
return 0;
}
},
Integer::sum);

var sigCount = visitor.visitLibrary(translator.getTranslatedLibrary().getLibrary(), null);

assertEquals(expectedSignatures, sigCount);
}

private static File getFile(String name) {
final URL resource = CMS146SignatureTest.class.getResource(name);

if (resource == null) {
throw new IllegalArgumentException("Cannot find file with name: " + name);
}

return new File(URLDecoder.decode(resource.getFile(), StandardCharsets.UTF_8));
}
}
4 changes: 4 additions & 0 deletions Src/java/elm-jaxb/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ dependencies {
testImplementation(project(":cql-to-elm"))
testImplementation(project(":ucum"))
testImplementation(project(":model-jaxb"))
testImplementation(project(":quick"))

testImplementation("org.xmlunit:xmlunit-assertj:2.10.0")
testImplementation("org.skyscreamer:jsonassert:1.5.1")
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package org.cqframework.cql.cql2elm;
package org.cqframework.cql.elm.serializing.jaxb;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.io.IOException;
Expand All @@ -7,12 +9,22 @@
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import org.cqframework.cql.cql2elm.CqlCompilerException.ErrorSeverity;
import org.cqframework.cql.cql2elm.CqlCompilerOptions;
import org.cqframework.cql.cql2elm.CqlTranslator;
import org.cqframework.cql.cql2elm.LibraryBuilder.SignatureLevel;
import org.cqframework.cql.cql2elm.LibraryManager;
import org.cqframework.cql.cql2elm.ModelManager;
import org.cqframework.cql.elm.utility.Visitors;
import org.hl7.elm.r1.Element;
import org.hl7.elm.r1.OperatorExpression;
import org.json.JSONException;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.skyscreamer.jsonassert.JSONAssert;

@Disabled(
"Replaced with a direct count of signatures in CMS146SignatureTest.java. Keeping to use for serialization tests.")
class CMS146JsonTest {

private static Object[][] sigFileAndSigLevel() {
Expand Down Expand Up @@ -55,4 +67,37 @@ private static File getFile(String name) {

return new File(URLDecoder.decode(resource.getFile(), StandardCharsets.UTF_8));
}

private static Object[][] sigCounts() {
return new Object[][] {
{SignatureLevel.None, 0},
{SignatureLevel.Differing, 3},
{SignatureLevel.Overloads, 11},
{SignatureLevel.All, 34}
};
}

@ParameterizedTest
@MethodSource("sigCounts")
void cms146SignatureLevels(SignatureLevel signatureLevel, int expectedSignatures) throws IOException {
final File cms146 = getFile("CMS146v2_Test_CQM.cql");
final ModelManager modelManager = new ModelManager();
final CqlTranslator translator = CqlTranslator.fromFile(
cms146,
new LibraryManager(modelManager, new CqlCompilerOptions(ErrorSeverity.Warning, signatureLevel)));

var visitor = Visitors.from(
(Element elm, Void context) -> {
if (elm instanceof OperatorExpression fd) {
return fd.getSignature().isEmpty() ? 0 : 1;
} else {
return 0;
}
},
Integer::sum);

var sigCount = visitor.visitLibrary(translator.getTranslatedLibrary().getLibrary(), null);

assertEquals(expectedSignatures, sigCount);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.cqframework.cql.cql2elm;
package org.cqframework.cql.elm.serializing.jaxb;

import java.io.File;
import java.io.IOException;
Expand All @@ -7,11 +7,18 @@
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import org.cqframework.cql.cql2elm.CqlCompilerException.ErrorSeverity;
import org.cqframework.cql.cql2elm.CqlCompilerOptions;
import org.cqframework.cql.cql2elm.CqlTranslator;
import org.cqframework.cql.cql2elm.LibraryBuilder.SignatureLevel;
import org.cqframework.cql.cql2elm.LibraryManager;
import org.cqframework.cql.cql2elm.ModelManager;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.xmlunit.assertj.XmlAssert;

@Disabled(
"Replaced with a direct count of signatures in CMS146SignatureTest.java. Keeping to use for serialization tests.")
class CMS146XmlTest {

private static Object[][] sigFileAndSigLevel() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
library CMS146 version '2'

using QUICK

valueset "Acute Pharyngitis": '2.16.840.1.113883.3.464.1003.102.12.1011'
valueset "Acute Tonsillitis": '2.16.840.1.113883.3.464.1003.102.12.1012'
valueset "Ambulatory/ED Visit": '2.16.840.1.113883.3.464.1003.101.12.1061'
valueset "Antibiotic Medications": '2.16.840.1.113883.3.464.1003.196.12.1001'
valueset "Group A Streptococcus Test": '2.16.840.1.113883.3.464.1003.198.12.1012'

parameter MeasurementPeriod default Interval[DateTime(2013, 1, 1, 0, 0, 0, 0), DateTime(2014, 1, 1, 0, 0, 0, 0))

context Patient

define InDemographic:
AgeInYearsAt(start of MeasurementPeriod) >= 2 and AgeInYearsAt(start of MeasurementPeriod) < 18

define Pharyngitis:
[Condition: "Acute Pharyngitis"] union [Condition: "Acute Tonsillitis"]

define Antibiotics:
[MedicationPrescription: "Antibiotic Medications"]

define TargetEncounters:
[Encounter: "Ambulatory/ED Visit"] E
with Pharyngitis P such that Interval[P.onsetDateTime, P.abatementDate] overlaps after E.period
with Antibiotics A such that A.dateWritten 3 days or less after start of E.period
where E.period during MeasurementPeriod

define TargetDiagnoses:
Pharyngitis P with TargetEncounters E such that Interval[P.onsetDateTime, P.abatementDate] overlaps after E.period

define HasPriorAntibiotics:
exists (Antibiotics A with TargetDiagnoses D such that A.dateWritten 30 days or less before D.onsetDateTime)

define HasTargetEncounter:
exists (TargetEncounters)

define InInitialPopulation:
InDemographic and HasTargetEncounter

define InDenominator:
true

define InDenominatorExclusions:
HasPriorAntibiotics

define InNumerator:
exists ([Observation: "Group A Streptococcus Test"] R where R.issued during MeasurementPeriod and R.valueQuantity is not null)

0 comments on commit 3b912cd

Please sign in to comment.