Search in sources :

Example 1 with DatetimeParameter

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

the class ParameterHelperTest method testResolveIntervalDatetimeParameter.

@Test
public void testResolveIntervalDatetimeParameter() {
    Map<String, Parameter> params = ParameterHelper.parseParameterArguments(Arrays.asList("test:interval:datetime,@2020-01-02T12:13:14,@2021-02-03T22:33:44"));
    assertEquals(1, params.size());
    IntervalParameter p = (IntervalParameter) params.get("test");
    DatetimeParameter start = (DatetimeParameter) p.getStart();
    assertEquals("@2020-01-02T12:13:14", start.getValue());
    DatetimeParameter end = (DatetimeParameter) p.getEnd();
    assertEquals("@2021-02-03T22:33:44", end.getValue());
}
Also used : DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) Test(org.junit.Test)

Example 2 with DatetimeParameter

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

the class ParameterHelperTest method testResolveDateTimeParameter.

@Test
public void testResolveDateTimeParameter() {
    Map<String, Parameter> params = ParameterHelper.parseParameterArguments(Arrays.asList("test:datetime:@2020-09-27T12:13:14"));
    assertEquals(1, params.size());
    DatetimeParameter p = (DatetimeParameter) params.get("test");
    assertNotNull("Parameter with expected name not found", p);
    assertEquals("Unexpected value", "@2020-09-27T12:13:14", p.getValue());
}
Also used : DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) Test(org.junit.Test)

Example 3 with DatetimeParameter

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

the class ParameterHelper method resolveDateTimeParameter.

/**
 * Decode command-line encoded parameter
 *
 * @param value encoded parameter value
 * @return decoded parameter value
 */
public static DatetimeParameter resolveDateTimeParameter(String value) {
    DatetimeParameter typedValue;
    typedValue = new DatetimeParameter(value);
    return typedValue;
}
Also used : DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter)

Example 4 with DatetimeParameter

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

the class CqlEvaluatorIntegrationTest method testConditionDateRangeCriteriaMatched.

@Test
public void testConditionDateRangeCriteriaMatched() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date = sdf.parse("2000-01-01");
    Condition condition = new Condition();
    condition.setId("condition");
    condition.setSubject(new Reference("Patient/123"));
    condition.setRecordedDate(date);
    // Wiremock does not support request matching withQueryParam() function does not support
    // the same parameter multiple times, so we do some regex work and try to make it
    // somewhat order independent while still readable.
    // @see https://github.com/tomakehurst/wiremock/issues/398
    MappingBuilder builder = get(urlMatching("/Condition\\?(recorded-date=[lg]e.*&){2}subject=Patient%2F123&_format=json"));
    mockFhirResourceRetrieval(builder, condition);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    CqlEvaluator evaluator = setupTestFor(patient, fhirConfig, "cql.condition", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
    Map<String, Parameter> parameters = new HashMap<>();
    parameters.put("MeasurementPeriod", new IntervalParameter(new DatetimeParameter("1999-01-01T00:00:00-05:00"), true, new DatetimeParameter("2000-01-01T00:00:00-05:00"), false));
    String expression = "ConditionInInterval";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("TestDateQuery", "1.0.0"), parameters, newPatientContext("123"), Collections.singleton(expression));
    Assert.assertEquals(1, actual.getExpressionResults().size());
    List<Object> value = (List) actual.getExpressionResults().get(expression);
    Assert.assertEquals(1, value.size());
    assertFhirEquals(condition, (IBaseResource) value.get(0));
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) HashMap(java.util.HashMap) Reference(org.hl7.fhir.r4.model.Reference) Patient(org.hl7.fhir.r4.model.Patient) CqlEvaluationResult(com.ibm.cohort.cql.evaluation.CqlEvaluationResult) Date(java.util.Date) MappingBuilder(com.github.tomakehurst.wiremock.client.MappingBuilder) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) List(java.util.List) SimpleDateFormat(java.text.SimpleDateFormat) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) Test(org.junit.Test)

Example 5 with DatetimeParameter

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

the class DefaultMeasurementPeriodStrategy method intervalToPair.

protected Pair<String, String> intervalToPair(IntervalParameter interval) {
    String start = null;
    String end = null;
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(TARGET_DATE_FORMAT);
    // weird CQL-language formatting such as the "@" char.
    if (interval.getStart() instanceof DatetimeParameter) {
        DateTime cqlType = null;
        DatetimeParameter dtStart = (DatetimeParameter) interval.getStart();
        cqlType = (DateTime) dtStart.toCqlType();
        start = formatter.format(cqlType.getDateTime());
        DatetimeParameter dtEnd = (DatetimeParameter) interval.getEnd();
        cqlType = (DateTime) dtEnd.toCqlType();
        end = formatter.format(cqlType.getDateTime());
    } else if (interval.getStart() instanceof DateParameter) {
        org.opencds.cqf.cql.engine.runtime.Date cqlType = null;
        DateParameter dStart = (DateParameter) interval.getStart();
        cqlType = (org.opencds.cqf.cql.engine.runtime.Date) dStart.toCqlType();
        start = formatter.format(cqlType.getDate());
        DateParameter dEnd = (DateParameter) interval.getEnd();
        cqlType = (org.opencds.cqf.cql.engine.runtime.Date) dEnd.toCqlType();
        end = formatter.format(cqlType.getDate());
    } else {
        throw new IllegalArgumentException(String.format("Unexpected interval data type '%s'", interval.getStart().getClass()));
    }
    return new ImmutablePair<String, String>(start, end);
}
Also used : DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) DateTimeFormatter(java.time.format.DateTimeFormatter) DateTime(org.opencds.cqf.cql.engine.runtime.DateTime) Date(java.util.Date)

Aggregations

DatetimeParameter (com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter)13 Test (org.junit.Test)10 IntervalParameter (com.ibm.cohort.cql.evaluation.parameters.IntervalParameter)8 Parameter (com.ibm.cohort.cql.evaluation.parameters.Parameter)7 IntegerParameter (com.ibm.cohort.cql.evaluation.parameters.IntegerParameter)6 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)6 ParameterDefinition (org.hl7.fhir.r4.model.ParameterDefinition)6 BooleanParameter (com.ibm.cohort.cql.evaluation.parameters.BooleanParameter)5 CodeParameter (com.ibm.cohort.cql.evaluation.parameters.CodeParameter)5 DateParameter (com.ibm.cohort.cql.evaluation.parameters.DateParameter)5 DecimalParameter (com.ibm.cohort.cql.evaluation.parameters.DecimalParameter)5 QuantityParameter (com.ibm.cohort.cql.evaluation.parameters.QuantityParameter)5 StringParameter (com.ibm.cohort.cql.evaluation.parameters.StringParameter)5 TimeParameter (com.ibm.cohort.cql.evaluation.parameters.TimeParameter)5 Date (java.util.Date)4 InstantType (org.hl7.fhir.r4.model.InstantType)4 Period (org.hl7.fhir.r4.model.Period)4 ConceptParameter (com.ibm.cohort.cql.evaluation.parameters.ConceptParameter)3 RatioParameter (com.ibm.cohort.cql.evaluation.parameters.RatioParameter)3 UnsupportedFhirTypeException (com.ibm.cohort.engine.measure.parameter.UnsupportedFhirTypeException)3