Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release bug fixes #1184

Merged
merged 9 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.hl7.cql.model.DataType;
import org.hl7.cql.model.NamedType;
import org.hl7.elm.r1.*;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
library TestForwardDeclaration

// This is to test that forward declartions for overloaded functions works as expected.

define function toString(value Concept):
if value is null
then 'null'
// The reference here to toString(value List<System.Code>) should _not_ result in a circular reference error
// The function signature is distinct, therefore is should be considered a different function.
else 'Concept { ' + toString(value.codes) + ' display: ' + value.display + ' }'

define function toString(value List<System.Code>):
Combine(
value C return 'Code: ' + C.display,
', '
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
library expression version '1.0.0'


define "return":
1 + 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
define "Test":
1+2
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static Object evaluate(Library library, Expression value, Map<String, Obj
// TODO: Cache for libraries?

CqlEngine engine = getEngine(library, parameters, evaluationDateTime);
return engine.visitExpression(value, engine.getState());
return engine.getEvaluationVisitor().visitExpression(value, engine.getState());
}

private static CqlEngine getEngine(Library library, Map<String, Object> parameters, ZonedDateTime evaluationDateTime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testFhirHelpersDstu2() throws UcumException {
String cql = getStringFromResourceStream("Dstu2/TestFHIRHelpersDstu2.cql");
var env = TranslatorHelper.getEnvironment();
Library library = TranslatorHelper.translate(cql, env.getLibraryManager());
CqlEngine engineVisitor = TranslatorHelper.getEngine(env);
CqlEngine engine = TranslatorHelper.getEngine(env);

VersionedIdentifier libraryId = TranslatorHelper.toElmIdentifier("TestFHIRHelpersDstu2", "0.1.0");

Expand All @@ -52,25 +52,25 @@ public void testFhirHelpersDstu2() throws UcumException {
modelResolver, FhirContext.forCached(FhirVersionEnum.DSTU2).newRestfulGenericClient(""));
CompositeDataProvider provider = new CompositeDataProvider(modelResolver, retrieveProvider);
//BaseFhirDataProvider provider = new FhirDataProviderDstu2();
engineVisitor.getState().getEnvironment().registerDataProvider("http://hl7.org/fhir", provider);
EvaluationResult evaluationResult = engineVisitor.evaluate(libraryId,
engine.getState().getEnvironment().registerDataProvider("http://hl7.org/fhir", provider);
EvaluationResult evaluationResult = engine.evaluate(libraryId,
null, null, null, null, null);

// TODO - millis shouldn't be populated - issue with DateTime.fromJavaDate(Date date)
Object result = evaluationResult.expressionResults.get("TestPeriodToInterval").value();
Object result = evaluationResult.forExpression("TestPeriodToInterval").value();
// Assert.assertEquals(((DateTime)((Interval) result).getStart()).getPartial(), new Partial(DateTime.getFields(7), new int[] {2017, 5, 6, 18, 8, 0, 0}));
// Assert.assertEquals(((DateTime)((Interval) result).getEnd()).getPartial(), new Partial(DateTime.getFields(7), new int[] {2017, 5, 6, 19, 8, 0, 0}));
result = evaluationResult.expressionResults.get("TestToQuantity").value();
result = evaluationResult.expressionResults.get("TestRangeToInterval").value();
result = evaluationResult.expressionResults.get("TestToCode").value();
result = evaluationResult.expressionResults.get("TestToConcept").value();
result = evaluationResult.expressionResults.get("TestToString").value();
result = evaluationResult.expressionResults.get("TestRequestStatusToString").value();
result = evaluationResult.expressionResults.get("TestToDateTime").value();
result = evaluationResult.expressionResults.get("TestToTime").value();
result = evaluationResult.expressionResults.get("TestToInteger").value();
result = evaluationResult.expressionResults.get("TestToDecimal").value();
result = evaluationResult.expressionResults.get("TestToBoolean").value();
result = evaluationResult.forExpression("TestToQuantity").value();
result = evaluationResult.forExpression("TestRangeToInterval").value();
result = evaluationResult.forExpression("TestToCode").value();
result = evaluationResult.forExpression("TestToConcept").value();
result = evaluationResult.forExpression("TestToString").value();
result = evaluationResult.forExpression("TestRequestStatusToString").value();
result = evaluationResult.forExpression("TestToDateTime").value();
result = evaluationResult.forExpression("TestToTime").value();
result = evaluationResult.forExpression("TestToInteger").value();
result = evaluationResult.forExpression("TestToDecimal").value();
result = evaluationResult.forExpression("TestToBoolean").value();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testFhirHelpersStu3() throws UcumException {
var env = TranslatorHelper.getEnvironment();
Library library = TranslatorHelper.translate(cql, env.getLibraryManager());

CqlEngine engineVisitor = TranslatorHelper.getEngine(env);
CqlEngine engine = TranslatorHelper.getEngine(env);

VersionedIdentifier libraryId = TranslatorHelper.toElmIdentifier("TestFHIRHelpers", "0.1.0");

Expand All @@ -53,28 +53,28 @@ public void testFhirHelpersStu3() throws UcumException {
CompositeDataProvider provider = new CompositeDataProvider(modelResolver, retrieveProvider);
// BaseFhirDataProvider provider = new
// FhirDataProviderStu3().setEndpoint("http://fhirtest.uhn.ca/baseDstu3");
engineVisitor.getState().getEnvironment().registerDataProvider("http://hl7.org/fhir", provider);
EvaluationResult evaluationResult = engineVisitor.evaluate(libraryId,
engine.getState().getEnvironment().registerDataProvider("http://hl7.org/fhir", provider);
EvaluationResult evaluationResult = engine.evaluate(libraryId,
null, null, null, null, null);

// TODO - fix
Object result = evaluationResult.expressionResults.get("TestPeriodToInterval").value();
Object result = evaluationResult.forExpression("TestPeriodToInterval").value();
// Assert.assertEquals(((DateTime)((Interval) result).getStart()).getPartial(),
// new Partial(DateTime.getFields(6), new int[] {2017, 5, 6, 18, 8, 0}));
// Assert.assertEquals(((DateTime)((Interval) result).getEnd()).getPartial(),
// new Partial(DateTime.getFields(6), new int[] {2017, 5, 6, 19, 8, 0}));
result = evaluationResult.expressionResults.get("TestToQuantity").value();
result = evaluationResult.forExpression("TestToQuantity").value();
// TODO: ModelInfo bug. Not aware of SimpleQuantity
result = evaluationResult.expressionResults.get("TestRangeToInterval").value();
result = evaluationResult.expressionResults.get("TestToCode").value();
result = evaluationResult.expressionResults.get("TestToConcept").value();
result = evaluationResult.expressionResults.get("TestToString").value();
result = evaluationResult.expressionResults.get("TestRequestStatusToString").value();
result = evaluationResult.expressionResults.get("TestToDateTime").value();
result = evaluationResult.expressionResults.get("TestToTime").value();
result = evaluationResult.expressionResults.get("TestToInteger").value();
result = evaluationResult.expressionResults.get("TestToDecimal").value();
result = evaluationResult.expressionResults.get("TestToBoolean").value();
result = evaluationResult.forExpression("TestRangeToInterval").value();
result = evaluationResult.forExpression("TestToCode").value();
result = evaluationResult.forExpression("TestToConcept").value();
result = evaluationResult.forExpression("TestToString").value();
result = evaluationResult.forExpression("TestRequestStatusToString").value();
result = evaluationResult.forExpression("TestToDateTime").value();
result = evaluationResult.forExpression("TestToTime").value();
result = evaluationResult.forExpression("TestToInteger").value();
result = evaluationResult.forExpression("TestToDecimal").value();
result = evaluationResult.forExpression("TestToBoolean").value();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ protected void runTest(org.hl7.fhirpath.tests.Test test, String basePathInput, F
}
}

CqlEngine engineVisitor = TranslatorHelper.getEngine(env);
engineVisitor.getCache().setExpressionCaching(false);
engineVisitor.getState().getEnvironment().registerDataProvider("http://hl7.org/fhir", provider);
CqlEngine engine = TranslatorHelper.getEngine(env);
engine.getCache().setExpressionCaching(false);
engine.getState().getEnvironment().registerDataProvider("http://hl7.org/fhir", provider);
if (resource != null) {
engineVisitor.getState().setParameter(null, resource.fhirType(), resource);
engine.getState().setParameter(null, resource.fhirType(), resource);
}

Object result = null;
Expand All @@ -189,10 +189,10 @@ protected void runTest(org.hl7.fhirpath.tests.Test test, String basePathInput, F
VersionedIdentifier libraryId = TranslatorHelper.toElmIdentifier("TestFHIRPath");
Map<VersionedIdentifier, Library> map = new HashMap<>();
map.put(libraryId, library);
EvaluationResult evaluationResult = engineVisitor.evaluate(libraryId,
EvaluationResult evaluationResult = engine.evaluate(libraryId,
Set.of("Test"), null, null, null, null);

result = evaluationResult.expressionResults.get("Test").value();
result = evaluationResult.forExpression("Test").value();
testPassed = invalidType.equals(InvalidType.FALSE);
} catch (Exception e) {
testPassed = invalidType.equals(InvalidType.TRUE);
Expand All @@ -217,7 +217,7 @@ protected void runTest(org.hl7.fhirpath.tests.Test test, String basePathInput, F
for (Object expectedResult : expectedResults) {
if (actualResultsIterator.hasNext()) {
Object actualResult = actualResultsIterator.next();
Boolean comparison = compareResults(expectedResult, actualResult, engineVisitor.getState(), resolver);
Boolean comparison = compareResults(expectedResult, actualResult, engine.getState(), resolver);
if (comparison == null || !comparison) {
System.out.println("Failing Test: " + test.getName());
System.out.println("- Expected Result: " + expectedResult + " (" + expectedResult.getClass() +")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static Environment getEnvironment(TerminologyProvider terminologyProvider
return new Environment(getLibraryManager(), null, terminologyProvider);
}

public static CqlEngine getEngineVisitor(TerminologyProvider terminologyProvider) {
public static CqlEngine getengine(TerminologyProvider terminologyProvider) {
return getEngine(getEnvironment(terminologyProvider));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,67 +42,67 @@ public Iterable<Object> retrieve(String context, String contextPath, Object cont

@Test
public void testWithCache() {
CqlEngine engineVisitor = getEngine();
engineVisitor.getState().getEnvironment().registerDataProvider("http://hl7.org/fhir", new CompositeDataProvider(r4ModelResolver, rp));
engineVisitor.getCache().setExpressionCaching(true);
EvaluationResult evaluationResult = engineVisitor.evaluate(library.getIdentifier(),
CqlEngine engine = getEngine();
engine.getState().getEnvironment().registerDataProvider("http://hl7.org/fhir", new CompositeDataProvider(r4ModelResolver, rp));
engine.getCache().setExpressionCaching(true);
EvaluationResult evaluationResult = engine.evaluate(library.getIdentifier(),
Set.of("Union"), null, null, null, null);


Object result = evaluationResult.expressionResults.get("Union").value();
Object result = evaluationResult.forExpression("Union").value();
assertThat(result, instanceOf(List.class));
assertThat(evaluationResult.expressionResults.get("Union").evaluatedResources().size(), is(2));
engineVisitor.getState().clearEvaluatedResources();
assertThat(evaluationResult.forExpression("Union").evaluatedResources().size(), is(2));
engine.getState().clearEvaluatedResources();


evaluationResult = engineVisitor.evaluate(library.getIdentifier(),
evaluationResult = engine.evaluate(library.getIdentifier(),
Set.of("Encounter"), null, null, null, null);
result = evaluationResult.expressionResults.get("Encounter").value();
result = evaluationResult.forExpression("Encounter").value();
assertThat(result, instanceOf(List.class));
assertThat(evaluationResult.expressionResults.get("Encounter").evaluatedResources().size(), is(1));
engineVisitor.getState().clearEvaluatedResources();
assertThat(evaluationResult.forExpression("Encounter").evaluatedResources().size(), is(1));
engine.getState().clearEvaluatedResources();


evaluationResult = engineVisitor.evaluate(library.getIdentifier(),
evaluationResult = engine.evaluate(library.getIdentifier(),
Set.of("Condition"), null, null, null, null);
result = evaluationResult.expressionResults.get("Condition").value();
result = evaluationResult.forExpression("Condition").value();
assertThat(result, instanceOf(List.class));
assertThat(evaluationResult.expressionResults.get("Condition").evaluatedResources().size(), is(1));
assertThat(evaluationResult.forExpression("Condition").evaluatedResources().size(), is(1));

}

@Test
public void testWithoutCache() {
CqlEngine engineVisitor = getEngine();
engineVisitor.getState().getEnvironment().registerDataProvider("http://hl7.org/fhir", new CompositeDataProvider(r4ModelResolver, rp));
EvaluationResult evaluationResult = engineVisitor.evaluate(library.getIdentifier(),
CqlEngine engine = getEngine();
engine.getState().getEnvironment().registerDataProvider("http://hl7.org/fhir", new CompositeDataProvider(r4ModelResolver, rp));
EvaluationResult evaluationResult = engine.evaluate(library.getIdentifier(),
Set.of("Union"), null, null, null, null);

Object result = evaluationResult.expressionResults.get("Union").value();
Object result = evaluationResult.forExpression("Union").value();
assertThat(result, instanceOf(List.class));
assertThat(evaluationResult.expressionResults.get("Union").evaluatedResources().size(), is(2));
engineVisitor.getState().clearEvaluatedResources();
assertThat(evaluationResult.forExpression("Union").evaluatedResources().size(), is(2));
engine.getState().clearEvaluatedResources();


evaluationResult = engineVisitor.evaluate(library.getIdentifier(),
evaluationResult = engine.evaluate(library.getIdentifier(),
Set.of("Encounter"), null, null, null, null);
result = evaluationResult.expressionResults.get("Encounter").value();
result = evaluationResult.forExpression("Encounter").value();
assertThat(result, instanceOf(List.class));
assertThat(evaluationResult.expressionResults.get("Encounter").evaluatedResources().size(), is(1));
engineVisitor.getState().clearEvaluatedResources();
assertThat(evaluationResult.forExpression("Encounter").evaluatedResources().size(), is(1));
engine.getState().clearEvaluatedResources();


evaluationResult = engineVisitor.evaluate(library.getIdentifier(),
evaluationResult = engine.evaluate(library.getIdentifier(),
Set.of("Condition"), null, null, null, null);
result = evaluationResult.expressionResults.get("Condition").value();
result = evaluationResult.forExpression("Condition").value();
assertThat(result, instanceOf(List.class));
assertThat(evaluationResult.expressionResults.get("Condition").evaluatedResources().size(), is(1));
assertThat(evaluationResult.forExpression("Condition").evaluatedResources().size(), is(1));

evaluationResult = engineVisitor.evaluate(library.getIdentifier(),
evaluationResult = engine.evaluate(library.getIdentifier(),
Set.of("Union"), null, null, null, null);
result = evaluationResult.expressionResults.get("Union").value();
result = evaluationResult.forExpression("Union").value();
assertThat(result, instanceOf(List.class));
assertThat(evaluationResult.expressionResults.get("Union").evaluatedResources().size(), is(2));
engineVisitor.getState().clearEvaluatedResources();
assertThat(evaluationResult.forExpression("Union").evaluatedResources().size(), is(2));
engine.getState().clearEvaluatedResources();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ public class TestCodeRef extends FhirExecutionTestBase {

// @Test
public void CodeRefTest1() {
CqlEngine engineVisitor = getEngine();
CqlEngine engine = getEngine();

EvaluationResult evaluationResult = engineVisitor.evaluate(library.getIdentifier(),
EvaluationResult evaluationResult = engine.evaluate(library.getIdentifier(),
Set.of("CodeRef1"), null, null, null, null);

assertTrue(evaluationResult.expressionResults.get("CodeRef1").value() != null);
assertTrue(evaluationResult.forExpression("CodeRef1").value() != null);
}

// @Test
public void CodeRefTest2() {
CqlEngine engineVisitor = getEngine();
CqlEngine engine = getEngine();

EvaluationResult evaluationResult = engineVisitor.evaluate(library.getIdentifier(),
EvaluationResult evaluationResult = engine.evaluate(library.getIdentifier(),
Set.of("CodeRef2"), null, null, null, null);

assertTrue(evaluationResult.expressionResults.get("CodeRef2").value() != null);
assertTrue(evaluationResult.forExpression("CodeRef2").value() != null);
}
}
Loading
Loading