use of org.hl7.elm.r1.FunctionRef in project clinical_quality_language by cqframework.
the class FunctionRefInvocation method setResolution.
@Override
public void setResolution(OperatorResolution resolution) {
super.setResolution(resolution);
FunctionRef fr = (FunctionRef) expression;
if (resolution.getLibraryName() != null && !resolution.getLibraryName().equals(fr.getLibraryName())) {
fr.setLibraryName(resolution.getLibraryName());
}
}
use of org.hl7.elm.r1.FunctionRef in project clinical_quality_language by cqframework.
the class ElmRequirementsContext method reportFunctionRef.
public void reportFunctionRef(FunctionRef functionRef) {
CompiledLibrary targetLibrary = prepareLibraryVisit(getCurrentLibraryIdentifier(), functionRef.getLibraryName());
try {
List<DataType> signature;
signature = new ArrayList<DataType>();
for (TypeSpecifier ts : functionRef.getSignature()) {
signature.add(typeResolver.resolveTypeSpecifier(ts));
}
// Signature sizes will only be different in the case that the signature is not present in the ELM, so needs to be constructed
if (signature.size() != functionRef.getOperand().size()) {
for (Expression e : functionRef.getOperand()) {
if (e.getResultType() != null) {
signature.add(e.getResultType());
} else if (e.getResultTypeName() != null) {
signature.add(typeResolver.resolveTypeName(e.getResultTypeName()));
} else if (e.getResultTypeSpecifier() != null) {
signature.add(typeResolver.resolveTypeSpecifier(e.getResultTypeSpecifier()));
} else {
// Signature could not be constructed, fall back to reporting all function defs
signature = null;
break;
}
}
}
Iterable<FunctionDef> fds = targetLibrary.resolveFunctionRef(functionRef.getName(), signature);
for (FunctionDef fd : fds) {
if (!visited.contains(fd)) {
visitor.visitElement(fd, this);
}
}
} finally {
unprepareLibraryVisit(functionRef.getLibraryName());
}
}
use of org.hl7.elm.r1.FunctionRef in project clinical_quality_language by cqframework.
the class FunctionRefInvocation method setOperands.
@Override
public void setOperands(Iterable<Expression> operands) {
List<Expression> expOperands = ((FunctionRef) expression).getOperand();
expOperands.clear();
for (Expression operand : operands) {
expOperands.add(operand);
}
}
use of org.hl7.elm.r1.FunctionRef 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