Search in sources :

Example 6 with StringParameter

use of com.ibm.cohort.cql.evaluation.parameters.StringParameter in project quality-measure-and-cohort-service by Alvearie.

the class R4ParameterDefinitionWithDefaultToCohortParameterConverterTest method testBase64Binary__shouldReturnStringParameter.

@Test
public void testBase64Binary__shouldReturnStringParameter() {
    ParameterDefinition parameterDefinition = getBaseParameterDefinition("base64Binary");
    String base64String = "AAA";
    Base64BinaryType fhirValue = new Base64BinaryType(base64String);
    parameterDefinition.addExtension(CDMConstants.PARAMETER_DEFAULT_URL, fhirValue);
    assertEquals(new StringParameter(base64String), R4ParameterDefinitionWithDefaultToCohortParameterConverter.toCohortParameter(parameterDefinition));
}
Also used : StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) Test(org.junit.Test)

Example 7 with StringParameter

use of com.ibm.cohort.cql.evaluation.parameters.StringParameter in project quality-measure-and-cohort-service by Alvearie.

the class SparkCqlEvaluatorTest method testGetFilteredRequestsGlobalParametersApplied.

@Test
public void testGetFilteredRequestsGlobalParametersApplied() {
    CqlEvaluationRequests requests = new CqlEvaluationRequests();
    requests.setGlobalParameters(new HashMap<String, Parameter>() {

        {
            put("param1", new IntegerParameter(10));
            put("param2", new StringParameter("10"));
            put("globalParam", new DecimalParameter("10.0"));
        }
    });
    CqlEvaluationRequest request = makeEvaluationRequest("context", "lib1", "1.0.0");
    request.setExpressionsByNames(new HashSet<>(Collections.singletonList("cohortOrig")));
    request.setParameters(new HashMap<String, Parameter>() {

        {
            put("param1", new IntegerParameter(1));
            put("param2", new StringParameter("1"));
            put("param3", new DecimalParameter("1.0"));
        }
    });
    CqlEvaluationRequest request2 = makeEvaluationRequest("context", "lib2", "1.0.0");
    request2.setExpressionsByNames(new HashSet<>(Collections.singletonList("cohortOrig")));
    List<CqlEvaluationRequest> evaluations = Arrays.asList(request, request2);
    requests.setEvaluations(evaluations);
    CqlEvaluationRequests actual = evaluator.getFilteredRequests(requests, null, null);
    for (CqlEvaluationRequest evaluation : actual.getEvaluations()) {
        if (evaluation.getDescriptor().getLibraryId().equals("lib1")) {
            assertEquals(4, evaluation.getParameters().size());
            assertEquals(new IntegerParameter(1), evaluation.getParameters().get("param1"));
            assertEquals(new StringParameter("1"), evaluation.getParameters().get("param2"));
            assertEquals(new DecimalParameter("1.0"), evaluation.getParameters().get("param3"));
            assertEquals(new DecimalParameter("10.0"), evaluation.getParameters().get("globalParam"));
        } else if (evaluation.getDescriptor().getLibraryId().equals("lib2")) {
            assertEquals(3, evaluation.getParameters().size());
            assertEquals(new IntegerParameter(10), evaluation.getParameters().get("param1"));
            assertEquals(new StringParameter("10"), evaluation.getParameters().get("param2"));
            assertEquals(new DecimalParameter("10.0"), evaluation.getParameters().get("globalParam"));
        } else {
            fail("Unexpected library encountered. Expected only lib1 and lib2.");
        }
    }
}
Also used : IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) CqlEvaluationRequest(com.ibm.cohort.cql.evaluation.CqlEvaluationRequest) CqlEvaluationRequests(com.ibm.cohort.cql.evaluation.CqlEvaluationRequests) Test(org.junit.Test)

Example 8 with StringParameter

use of com.ibm.cohort.cql.evaluation.parameters.StringParameter in project quality-measure-and-cohort-service by Alvearie.

the class CqlEvaluationRequestsTest method testSetGet.

@Test
public void testSetGet() {
    Map<String, Parameter> globalParameters = new HashMap<>();
    globalParameters.put("String", new StringParameter("Hello,World"));
    globalParameters.put("Integer", new IntegerParameter(10));
    Map<String, Parameter> localParameters = new HashMap<>();
    localParameters.put("String", new StringParameter("Goodbye, Cruel World"));
    localParameters.put("Float", new DecimalParameter("1.29f"));
    CqlLibraryDescriptor desc = new CqlLibraryDescriptor().setLibraryId("SampleLibrary").setVersion("1.0.0");
    CqlExpressionConfiguration expressionConfiguration = new CqlExpressionConfiguration();
    expressionConfiguration.setName("IsFemale");
    CqlEvaluationRequest r1 = new CqlEvaluationRequest();
    r1.setDescriptor(desc);
    r1.setParameters(localParameters);
    r1.setExpressions(Collections.singleton(expressionConfiguration));
    r1.setContextKey("Patient");
    r1.setContextValue("NA");
    assertEquals(desc, r1.getDescriptor());
    assertEquals(localParameters, r1.getParameters());
    assertEquals(Collections.singleton(expressionConfiguration), r1.getExpressions());
    assertEquals("Patient", r1.getContextKey());
    assertEquals("NA", r1.getContextValue());
    CqlEvaluationRequests requests = new CqlEvaluationRequests();
    requests.setGlobalParameters(globalParameters);
    requests.setEvaluations(Arrays.asList(r1));
    assertEquals(globalParameters, requests.getGlobalParameters());
    assertEquals(1, requests.getEvaluations().size());
}
Also used : IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) HashMap(java.util.HashMap) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) CqlLibraryDescriptor(com.ibm.cohort.cql.library.CqlLibraryDescriptor) Test(org.junit.Test)

Example 9 with StringParameter

use of com.ibm.cohort.cql.evaluation.parameters.StringParameter in project quality-measure-and-cohort-service by Alvearie.

the class CqlContextFactoryTest method testCreateContextSuccess.

@Test
public void testCreateContextSuccess() {
    boolean expectedDebug = true;
    ZonedDateTime expectedEvaluationDateTime = ZonedDateTime.of(LocalDateTime.of(2001, 10, 2, 11, 12, 13), ZoneId.of("America/New_York"));
    PriorityCqlLibraryProvider libraryProvider = new PriorityCqlLibraryProvider(new ClasspathCqlLibraryProvider("cql", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH));
    CqlToElmTranslator translator = new CqlToElmTranslator();
    TranslatingCqlLibraryProvider translatingProvider = new TranslatingCqlLibraryProvider(libraryProvider, translator);
    CqlVersionedIdentifier topLevelLibraryIdentifier = new CqlVersionedIdentifier("MyCQL", "1.0.0");
    CqlTerminologyProvider terminologyProvider = new UnsupportedTerminologyProvider();
    CqlDataProvider dataProvider = mock(CqlDataProvider.class);
    Pair<String, String> contextData = Pair.of("Patient", "123");
    Map<String, Parameter> expectedParams = new HashMap<>();
    expectedParams.put("P1", new StringParameter("MyString"));
    expectedParams.put("P2", new IntegerParameter(10));
    CqlContextFactory cqlContextFactory = spy(CqlContextFactory.class);
    Context context = cqlContextFactory.createContext(translatingProvider, topLevelLibraryIdentifier, terminologyProvider, dataProvider, expectedEvaluationDateTime, contextData, expectedParams, expectedDebug ? CqlDebug.DEBUG : CqlDebug.NONE);
    assertEquals(expectedDebug, context.getDebugMap().getIsLoggingEnabled());
    assertEquals(expectedEvaluationDateTime.toInstant(), context.getEvaluationDateTime().getDateTime().toZonedDateTime().toInstant());
    context.enterContext(contextData.getKey());
    assertEquals(contextData.getValue(), context.getCurrentContextValue());
    assertEquals(topLevelLibraryIdentifier.getId(), context.getCurrentLibrary().getIdentifier().getId());
    assertEquals(topLevelLibraryIdentifier.getVersion(), context.getCurrentLibrary().getIdentifier().getVersion());
    for (Map.Entry<String, Parameter> entry : expectedParams.entrySet()) {
        Object actualValue = context.resolveParameterRef(null, entry.getKey());
        assertEquals(entry.getValue().toCqlType(), actualValue);
    }
    // Once more just to check that caching is working. Using a different data provider because that is
    // how we will actually use it at runtime.
    CqlDataProvider dataProvider2 = mock(CqlDataProvider.class);
    cqlContextFactory.createContext(translatingProvider, topLevelLibraryIdentifier, terminologyProvider, dataProvider2, expectedEvaluationDateTime, contextData, expectedParams, expectedDebug ? CqlDebug.DEBUG : CqlDebug.NONE);
    verify(cqlContextFactory, times(1)).createContext(any(ContextCacheKey.class));
}
Also used : Context(org.opencds.cqf.cql.engine.execution.Context) UnsupportedTerminologyProvider(com.ibm.cohort.cql.terminology.UnsupportedTerminologyProvider) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) TranslatingCqlLibraryProvider(com.ibm.cohort.cql.translation.TranslatingCqlLibraryProvider) HashMap(java.util.HashMap) CqlToElmTranslator(com.ibm.cohort.cql.translation.CqlToElmTranslator) PriorityCqlLibraryProvider(com.ibm.cohort.cql.library.PriorityCqlLibraryProvider) ZonedDateTime(java.time.ZonedDateTime) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) ClasspathCqlLibraryProvider(com.ibm.cohort.cql.library.ClasspathCqlLibraryProvider) CqlTerminologyProvider(com.ibm.cohort.cql.terminology.CqlTerminologyProvider) ContextCacheKey(com.ibm.cohort.cql.evaluation.CqlContextFactory.ContextCacheKey) CqlDataProvider(com.ibm.cohort.cql.data.CqlDataProvider) HashMap(java.util.HashMap) Map(java.util.Map) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) Test(org.junit.Test)

Aggregations

StringParameter (com.ibm.cohort.cql.evaluation.parameters.StringParameter)9 Test (org.junit.Test)8 IntegerParameter (com.ibm.cohort.cql.evaluation.parameters.IntegerParameter)6 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)6 DecimalParameter (com.ibm.cohort.cql.evaluation.parameters.DecimalParameter)5 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)4 ParameterDefinition (org.hl7.fhir.r4.model.ParameterDefinition)4 BooleanParameter (com.ibm.cohort.cql.evaluation.parameters.BooleanParameter)3 CodeParameter (com.ibm.cohort.cql.evaluation.parameters.CodeParameter)3 DateParameter (com.ibm.cohort.cql.evaluation.parameters.DateParameter)3 DatetimeParameter (com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter)3 QuantityParameter (com.ibm.cohort.cql.evaluation.parameters.QuantityParameter)3 TimeParameter (com.ibm.cohort.cql.evaluation.parameters.TimeParameter)3 HashMap (java.util.HashMap)3 Base64BinaryType (org.hl7.fhir.r4.model.Base64BinaryType)3 StringType (org.hl7.fhir.r4.model.StringType)3 UriType (org.hl7.fhir.r4.model.UriType)3 ConceptParameter (com.ibm.cohort.cql.evaluation.parameters.ConceptParameter)2 RatioParameter (com.ibm.cohort.cql.evaluation.parameters.RatioParameter)2 UnsupportedFhirTypeException (com.ibm.cohort.engine.measure.parameter.UnsupportedFhirTypeException)2