use of com.ibm.cohort.cql.util.PrefixStringMatcher in project quality-measure-and-cohort-service by Alvearie.
the class AnyColumnFunctions method AnyColumn.
public static Object AnyColumn(Object object, String fieldPrefix) {
DataRow dataRow = (DataRow) object;
StringMatcher matcher = new PrefixStringMatcher(fieldPrefix);
return dataRow.getFieldNames().stream().filter(matcher).map(dataRow::getValue).collect(Collectors.toList());
}
use of com.ibm.cohort.cql.util.PrefixStringMatcher in project quality-measure-and-cohort-service by Alvearie.
the class DataTypeRequirementsProcessorTest method testAnyColumnRequirements.
@Test
public void testAnyColumnRequirements() throws Exception {
String basePath = "src/test/resources";
Map<String, Set<StringMatcher>> reqsByDataType = runPatternTest(basePath + "/any-column/cql", basePath + "/alltypes/modelinfo/alltypes-modelinfo-1.0.0.xml", null, x -> x.getFileName().toString().equals("MeasureAnyColumn-1.0.0.cql"));
Map<String, Set<StringMatcher>> expectations = new HashMap<>();
expectations.put("A", new HashSet<>(Arrays.asList(new PrefixStringMatcher("code_col"))));
expectations.put("B", new HashSet<>(Arrays.asList(new RegexStringMatcher("integer_col"))));
expectations.put("C", new HashSet<>(Arrays.asList(new RegexStringMatcher(".*_decimal"))));
assertEquals(expectations, reqsByDataType);
}
use of com.ibm.cohort.cql.util.PrefixStringMatcher in project quality-measure-and-cohort-service by Alvearie.
the class AnyColumnVisitor method visitFunctionRef.
@Override
public Object visitFunctionRef(FunctionRef elm, AnyColumnContext context) {
if (AnyColumnFunctions.FUNCTION_NAMES.contains(elm.getName())) {
if (elm.getOperand().size() == 2) {
QName dataType = ((As) elm.getOperand().get(0)).getOperand().getResultTypeName();
// TODO - validate that the first operand is a model object. We really should be doing that at the
// method declaration level instead of Choice<Any>, but that will require the model
// to have a base class that everything extends from.
String columnMatchLogic = null;
if (elm.getOperand().get(1) instanceof Literal) {
columnMatchLogic = ((Literal) elm.getOperand().get(1)).getValue();
} else {
throw new IllegalArgumentException(String.format("Second argument to %s function at %s must be a literal", elm.getName(), elm.getLocator()));
}
StringMatcher matcher = null;
if (elm.getName().equals(AnyColumnFunctions.FUNC_ANY_COLUMN)) {
matcher = new PrefixStringMatcher(columnMatchLogic);
} else if (elm.getName().equals(AnyColumnFunctions.FUNC_ANY_COLUMN_REGEX)) {
matcher = new RegexStringMatcher(columnMatchLogic);
} else {
throw new IllegalArgumentException(String.format("Found declared, but unsupported AnyColumn function %s at %s", elm.getName(), elm.getLocator()));
}
context.reportAnyColumn(dataType, matcher);
} else {
throw new IllegalArgumentException(String.format("%s function at %s should have exactly two arguments", elm.getName(), elm.getLocator()));
}
}
return super.visitFunctionRef(elm, context);
}
Aggregations