use of org.hl7.elm.r1.FunctionDef 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.FunctionDef in project clinical_quality_language by cqframework.
the class DataRequirementsProcessor method extractParameters.
private List<ParameterDefinition> extractParameters(ElmRequirementsContext context, ElmRequirements requirements, VersionedIdentifier libraryIdentifier, Iterable<ExpressionDef> expressionDefs) {
List<ParameterDefinition> result = new ArrayList<>();
// TODO: Support library qualified parameters
// Until then, name clashes should result in a warning
Map<String, ParameterDefinition> pds = new HashMap<String, ParameterDefinition>();
for (ElmRequirement def : requirements.getParameterDefs()) {
ParameterDefinition pd = toParameterDefinition(def.getLibraryIdentifier(), (ParameterDef) def.getElement());
if (pds.containsKey(pd.getName())) {
ParameterDefinition existingPd = pds.get(pd.getName());
if (!isEquivalentDefinition(existingPd, pd)) {
// Issue a warning that the parameter has a duplicate name but an incompatible type
validationMessages.add(new ValidationMessage(ValidationMessage.Source.Publisher, ValidationMessage.IssueType.NOTSUPPORTED, "CQL Library Packaging", String.format("Parameter declaration %s.%s is already defined in a different library with a different type. Parameter binding may result in errors during evaluation.", def.getLibraryIdentifier().getId(), pd.getName()), ValidationMessage.IssueSeverity.WARNING));
}
} else {
pds.put(pd.getName(), pd);
result.add(pd);
}
}
for (ExpressionDef def : expressionDefs) {
if (def != null && !(def instanceof FunctionDef) && (def.getAccessLevel() == null || def.getAccessLevel() == AccessModifier.PUBLIC)) {
result.add(toOutputParameterDefinition(libraryIdentifier, def));
}
}
return result;
}
use of org.hl7.elm.r1.FunctionDef in project clinical_quality_language by cqframework.
the class CommentTests method testTags.
@Test
public void testTags() throws IOException {
CqlTranslator translator = TestUtils.runSemanticTest("TestTags.cql", 0);
CompiledLibrary library = translator.getTranslatedLibrary();
assertThat(library.getLibrary().getAnnotation(), notNullValue());
Annotation a = null;
for (Object o : library.getLibrary().getAnnotation()) {
if (o instanceof Annotation) {
a = (Annotation) o;
}
}
assertThat(a, notNullValue());
assertThat(a.getT(), notNullValue());
assertThat(a.getT().size(), equalTo(3));
for (int i = 0; i < a.getT().size(); i++) {
Tag t = a.getT().get(i);
switch(i) {
case 0:
assertThat(t.getName(), equalTo("author"));
assertThat(t.getValue(), equalTo("Frederic Chopin"));
break;
case 1:
assertThat(t.getName(), equalTo("description"));
assertThat(t.getValue(), equalTo("Test tags"));
break;
case 2:
assertThat(t.getName(), equalTo("allowFluent"));
assertThat(t.getValue(), equalTo("true"));
break;
}
}
ExpressionDef d = library.resolveExpressionRef("TestExpression");
assertThat(d.getAnnotation(), notNullValue());
for (Object o : d.getAnnotation()) {
if (o instanceof Annotation) {
a = (Annotation) o;
}
}
assertThat(a, notNullValue());
assertThat(a.getT(), notNullValue());
assertThat(a.getT().size(), equalTo(2));
for (int i = 0; i < a.getT().size(); i++) {
Tag t = a.getT().get(i);
switch(i) {
case 0:
assertThat(t.getName(), equalTo("author"));
assertThat(t.getValue(), equalTo("Frederic Chopin"));
break;
case 1:
assertThat(t.getName(), equalTo("description"));
assertThat(t.getValue(), equalTo("Test tags"));
break;
}
}
for (ExpressionDef e : library.getLibrary().getStatements().getDef()) {
if (e instanceof FunctionDef) {
d = e;
break;
}
}
assertThat(d.getAnnotation(), notNullValue());
for (Object o : d.getAnnotation()) {
if (o instanceof Annotation) {
a = (Annotation) o;
}
}
assertThat(a, notNullValue());
assertThat(a.getT(), notNullValue());
assertThat(a.getT().size(), equalTo(2));
for (int i = 0; i < a.getT().size(); i++) {
Tag t = a.getT().get(i);
switch(i) {
case 0:
assertThat(t.getName(), equalTo("author"));
assertThat(t.getValue(), equalTo("Frederic Chopin"));
break;
case 1:
assertThat(t.getName(), equalTo("description"));
assertThat(t.getValue(), equalTo("Test tags"));
break;
}
}
d = library.resolveExpressionRef("TestMultiline");
assertThat(d.getAnnotation(), notNullValue());
for (Object o : d.getAnnotation()) {
if (o instanceof Annotation) {
a = (Annotation) o;
}
}
assertThat(a, notNullValue());
assertThat(a.getT(), notNullValue());
assertThat(a.getT().size(), equalTo(3));
for (int i = 0; i < a.getT().size(); i++) {
Tag t = a.getT().get(i);
switch(i) {
case 0:
assertThat(t.getName(), equalTo("author"));
assertThat(t.getValue(), equalTo("Frederic Chopin"));
break;
case 1:
assertThat(t.getName(), equalTo("description"));
assertThat(t.getValue(), equalTo("This is a multi-line description that\n spans multiple lines."));
break;
case 2:
assertThat(t.getName(), equalTo("following"));
assertThat(t.getValue(), equalTo("true"));
break;
}
}
}
use of org.hl7.elm.r1.FunctionDef in project clinical_quality_language by cqframework.
the class SystemLibraryHelper method add.
private static void add(CompiledLibrary systemLibrary, TypeBuilder tb, Operator operator) {
// In the case that an operator is added directly, manufacture a FunctionDef so it can be referred to in ELM Analysis
FunctionDef fd = new FunctionDef();
fd.setName(operator.getName());
int n = 0;
for (DataType dataType : operator.getSignature().getOperandTypes()) {
n++;
OperandDef od = new OperandDef().withName(String.format("param%d", n));
if (dataType instanceof NamedType) {
od.setOperandType(tb.dataTypeToQName(dataType));
} else {
od.setOperandTypeSpecifier(tb.dataTypeToTypeSpecifier(dataType));
}
od.setResultType(dataType);
fd.getOperand().add(od);
}
operator.setFunctionDef(fd);
systemLibrary.add(fd, operator);
}
Aggregations