Skip to content

Commit

Permalink
Set ValueSetRef.preserve to true for included value sets (#1409)
Browse files Browse the repository at this point in the history
* #1407: Set preserve to true for included value sets

* Clean up tests
  • Loading branch information
antvaset committed Aug 30, 2024
1 parent 05c2bd3 commit dd98ccc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2941,6 +2941,9 @@ public Expression resolveAccessor(Expression left, String memberIdentifier) {
ValueSetRef result =
of.createValueSetRef().withLibraryName(libraryName).withName(memberIdentifier);
result.setResultType(element.getResultType());
if (isCompatibleWith("1.5")) {
result.setPreserve(true);
}
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

import java.io.IOException;
import java.util.HashMap;
Expand Down Expand Up @@ -772,6 +770,26 @@ public void testIdentifierDoesNotResolveCaseMismatchExistIdentifier() throws IOE
assertThat(warnings, hasSize(0));
}

@Test
void issue1407() throws IOException {
assertNull(issue1407GetIsPreserve("1.4"));
assertTrue(issue1407GetIsPreserve("1.5"));
}

private Boolean issue1407GetIsPreserve(String compatibilityLevel) throws IOException {
CqlTranslator translator = runSemanticTest(
"LibraryTests/Issue1407.cql", 0, new CqlCompilerOptions().withCompatibilityLevel(compatibilityLevel));
var library = translator.toELM();
var testExpression = library.getStatements().getDef().stream()
.filter(def -> def.getName().equals("TestStatement"))
.findFirst()
.orElseThrow()
.getExpression();

assertThat(testExpression, instanceOf(ValueSetRef.class));
return ((ValueSetRef) testExpression).isPreserve();
}

private CqlTranslator runSemanticTest(String testFileName) throws IOException {
return runSemanticTest(testFileName, 0);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
library Issue1407

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.1' called FHIRHelpers

include Issue1407ValueSets

context Patient

define TestStatement: Issue1407ValueSets.TestValueSet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
library Issue1407ValueSets

using FHIR version '4.0.1'

valueset TestValueSet: 'garb'
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.opencds.cqf.cql.engine.execution.CqlConceptTest.assertEqual;

import java.util.Collections;
import java.util.List;
import org.cqframework.cql.cql2elm.LibraryManager;
import org.cqframework.cql.cql2elm.ModelManager;
import org.junit.jupiter.api.Test;
import org.opencds.cqf.cql.engine.runtime.Code;
import org.opencds.cqf.cql.engine.terminology.CodeSystemInfo;
import org.opencds.cqf.cql.engine.terminology.TerminologyProvider;
import org.opencds.cqf.cql.engine.terminology.ValueSetInfo;
import org.opencds.cqf.cql.engine.runtime.ValueSet;

class IncludedValueSetRefTest {

Expand All @@ -21,33 +15,15 @@ void all_included_valueset() {
LibraryManager libraryManager = new LibraryManager(new ModelManager());
libraryManager.getLibrarySourceLoader().registerProvider(new TestLibrarySourceProvider());

Code expected = new Code().withCode("M").withSystem("http://test.com/system");
TerminologyProvider terminologyProvider = new TerminologyProvider() {
public boolean in(Code code, ValueSetInfo valueSet) {
return true;
}

public Iterable<Code> expand(ValueSetInfo valueSet) {
return Collections.singletonList(expected);
}

public Code lookup(Code code, CodeSystemInfo codeSystem) {
return null;
}
};

Environment environment = new Environment(libraryManager, null, terminologyProvider);
Environment environment = new Environment(libraryManager);

CqlEngine engine = new CqlEngine(environment);

var results = engine.evaluate(CqlTestBase.toElmIdentifier("IncludedValueSetRefTest"));

@SuppressWarnings("unchecked")
List<Code> actual =
(List<Code>) results.forExpression("IncludedValueSet").value();
assertNotNull(actual);
assertEquals(1, actual.size());
var actual = (ValueSet) results.forExpression("IncludedValueSet").value();

assertEqual(expected, actual.get(0));
assertNotNull(actual);
assertEquals("http://test/common", actual.getId());
}
}

0 comments on commit dd98ccc

Please sign in to comment.