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

Evaluate simple math as CQL Expressions #1407

Closed
vitorpamplona opened this issue May 19, 2022 · 1 comment
Closed

Evaluate simple math as CQL Expressions #1407

vitorpamplona opened this issue May 19, 2022 · 1 comment
Labels
effort:small Small effort - 2 days P2 Medium priority issue

Comments

@vitorpamplona
Copy link
Collaborator

vitorpamplona commented May 19, 2022

Is your feature request related to a problem? Please describe.

The following test case demonstrates the use of an ADD operation inside a CQL expression. This test must pass.

import ca.uhn.fhir.context.FhirContext
import ca.uhn.fhir.context.FhirVersionEnum
import com.google.common.truth.Truth.assertThat
import org.hl7.fhir.r4.model.IntegerType
import org.hl7.fhir.r4.model.Parameters
import org.junit.Test
import org.opencds.cqf.cql.engine.fhir.converter.FhirTypeConverterFactory
import org.opencds.cqf.cql.evaluator.builder.CqlEvaluatorBuilder
import org.opencds.cqf.cql.evaluator.builder.EndpointConverter
import org.opencds.cqf.cql.evaluator.builder.data.DataProviderFactory
import org.opencds.cqf.cql.evaluator.builder.data.FhirModelResolverFactory
import org.opencds.cqf.cql.evaluator.builder.data.TypedRetrieveProviderFactory
import org.opencds.cqf.cql.evaluator.builder.library.LibraryContentProviderFactory
import org.opencds.cqf.cql.evaluator.builder.library.TypedLibraryContentProviderFactory
import org.opencds.cqf.cql.evaluator.builder.terminology.TerminologyProviderFactory
import org.opencds.cqf.cql.evaluator.builder.terminology.TypedTerminologyProviderFactory
import org.opencds.cqf.cql.evaluator.cql2elm.util.LibraryVersionSelector
import org.opencds.cqf.cql.evaluator.expression.ExpressionEvaluator
import org.opencds.cqf.cql.evaluator.fhir.adapter.r4.AdapterFactory
import org.opencds.cqf.cql.evaluator.library.CqlFhirParametersConverter

class ExpressionEvaluatorTest {
  @Test
  fun testSimpleMathExpression() {
    val fhirContext = FhirContext.forCached(FhirVersionEnum.R4)
    val adapterFactory = AdapterFactory()

    // Creates a Expression Evaluator without any loaders
    var evaluator = ExpressionEvaluator(
      fhirContext,
      CqlFhirParametersConverter(
        fhirContext, adapterFactory,
        FhirTypeConverterFactory().create(fhirContext.getVersion().getVersion())
      ),
      LibraryContentProviderFactory(
        fhirContext, adapterFactory,
        emptySet<TypedLibraryContentProviderFactory>(),
        LibraryVersionSelector(adapterFactory)
      ),
      DataProviderFactory(
        fhirContext, emptySet<FhirModelResolverFactory>(), emptySet<TypedRetrieveProviderFactory>()
      ),
      TerminologyProviderFactory(
        fhirContext, emptySet<TypedTerminologyProviderFactory>()
      ),
      EndpointConverter(adapterFactory),
      FhirModelResolverFactory()
    ) { CqlEvaluatorBuilder() }

    val params = evaluator.evaluate("1 + 3",null,null,null,null,null,null,null,null,null) as Parameters
    val result = (params.getParameter("return") as IntegerType).value

    assertThat(result).isEqualTo(4);
  }
}

Describe the solution you'd like
The expression 1+3 should be assembled into a CQL library, compiled to ELM and evaluated with the CQL Evaluator.

Describe alternatives you've considered

Additional context
Depends on Issue #1365, and PRs #1326 and #1395, as well as:

Would you like to work on the issue?
Yes

@vitorpamplona vitorpamplona changed the title Evaluate simple CQL Expressions Evaluate simple math as CQL Expressions May 19, 2022
@Tarun-Bhardwaj Tarun-Bhardwaj added workflow P2 Medium priority issue effort:small Small effort - 2 days and removed Triage labels Jul 5, 2022
@vitorpamplona
Copy link
Collaborator Author

Fixed on #1603

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort:small Small effort - 2 days P2 Medium priority issue
Projects
Status: Complete
Development

No branches or pull requests

3 participants