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());
}
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());
}
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;
}
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));
}
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);
}
Aggregations