diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/Invocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/Invocation.java deleted file mode 100644 index 3e55834fa..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/Invocation.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.cqframework.cql.cql2elm.model; - -import java.util.List; -import org.hl7.cql.model.DataType; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.TypeSpecifier; - -/** - * The Invocation interface is used to represent an invocation of an operator or function in the ELM model. - * The ELM classes have named properties for their operands, but the Invocation interface uses a list of expressions to represent the operands. - * The implementations of this interface are responsible for managing the mapping between the list of expressions and the - * properties of the ELM class. For example, the DateInvocation class maps properties for year, month, and day to the first, second, and third - * expressions in the list of operands. This allows Invocations to be handled generically in the CQL-to-ELM translation process. - */ -public interface Invocation { - List getSignature(); - - void setSignature(List signature); - - List getOperands(); - - void setOperands(List operands); - - void setResultType(DataType resultType); - - Expression getExpression(); - - void setResolution(OperatorResolution resolution); - - OperatorResolution getResolution(); -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/Invocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/Invocation.kt new file mode 100644 index 000000000..6298d8165 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/Invocation.kt @@ -0,0 +1,27 @@ +package org.cqframework.cql.cql2elm.model + +import org.hl7.cql.model.DataType +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.TypeSpecifier + +/** + * The Invocation interface is used to represent an invocation of an operator or function in the ELM + * model. The ELM classes have named properties for their operands, but the Invocation interface + * uses a list of expressions to represent the operands. The implementations of this interface are + * responsible for managing the mapping between the list of expressions and the properties of the + * ELM class. For example, the DateInvocation class maps properties for year, month, and day to the + * first, second, and third expressions in the list of operands. This allows Invocations to be + * handled generically in the CQL-to-ELM translation process. + */ +interface Invocation { + + var signature: List<@JvmSuppressWildcards TypeSpecifier> + + var operands: List<@JvmSuppressWildcards Expression> + + var resultType: DataType? + + val expression: Expression + + var resolution: OperatorResolution? +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AbstractExpressionInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AbstractExpressionInvocation.java deleted file mode 100644 index e9212505f..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AbstractExpressionInvocation.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.List; -import org.apache.commons.lang3.Validate; -import org.cqframework.cql.cql2elm.model.Invocation; -import org.cqframework.cql.cql2elm.model.OperatorResolution; -import org.hl7.cql.model.DataType; -import org.hl7.elm.r1.Expression; - -/** - * The AbstractExpressionInvocation can be used to more simply make invocations for classes that only extend - * Expression. - */ -abstract class AbstractExpressionInvocation implements Invocation { - protected AbstractExpressionInvocation(E expression) { - this.expression = requireNonNull(expression, "expression is null."); - } - - protected E expression; - - @Override - public void setResultType(DataType resultType) { - expression.setResultType(resultType); - } - - @Override - public Expression getExpression() { - return expression; - } - - protected static void require(boolean condition, String message) { - Validate.isTrue(condition, message); - } - - protected Expression requireSingleton(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(operands.size() == 1, "Unary operator expected."); - return operands.get(0); - } - - private OperatorResolution resolution; - - public OperatorResolution getResolution() { - return resolution; - } - - public void setResolution(OperatorResolution resolution) { - this.resolution = resolution; - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AbstractExpressionInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AbstractExpressionInvocation.kt new file mode 100644 index 000000000..27d5012bc --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AbstractExpressionInvocation.kt @@ -0,0 +1,22 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.cqframework.cql.cql2elm.model.Invocation +import org.cqframework.cql.cql2elm.model.OperatorResolution +import org.hl7.cql.model.DataType +import org.hl7.elm.r1.Expression + +/** + * The AbstractExpressionInvocation can be used to more simply make invocations for classes that + * only extend Expression. + */ +abstract class AbstractExpressionInvocation(override val expression: E) : + Invocation { + + override var resultType: DataType? + get() = expression.resultType + set(resultType) { + expression.resultType = resultType + } + + override var resolution: OperatorResolution? = null +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AggregateExpressionInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AggregateExpressionInvocation.java deleted file mode 100644 index 71b734e41..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AggregateExpressionInvocation.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import java.util.Collections; -import java.util.List; -import org.hl7.elm.r1.AggregateExpression; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.TypeSpecifier; - -public class AggregateExpressionInvocation extends AbstractExpressionInvocation { - public AggregateExpressionInvocation(A expression) { - super(expression); - } - - @Override - public List getOperands() { - return Collections.singletonList(expression.getSource()); - } - - @Override - public void setOperands(List operands) { - expression.setSource(requireSingleton(operands)); - } - - @Override - public List getSignature() { - return expression.getSignature(); - } - - @Override - public void setSignature(List signature) { - for (TypeSpecifier typeSpecifier : signature) { - expression.getSignature().add(typeSpecifier); - } - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AggregateExpressionInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AggregateExpressionInvocation.kt new file mode 100644 index 000000000..09594c784 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AggregateExpressionInvocation.kt @@ -0,0 +1,22 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.AggregateExpression +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.TypeSpecifier + +class AggregateExpressionInvocation(expression: A) : + AbstractExpressionInvocation(expression) { + + override var operands: List + get() = listOf(expression.source) + set(operands) { + require(operands.size == 1) { "Unary operator expected." } + expression.source = operands[0] + } + + override var signature: List + get() = expression.signature + set(signature) { + expression.signature = signature + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AnyInCodeSystemInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AnyInCodeSystemInvocation.java deleted file mode 100644 index cea054672..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AnyInCodeSystemInvocation.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.ArrayList; -import java.util.List; -import org.hl7.elm.r1.AnyInCodeSystem; -import org.hl7.elm.r1.Expression; - -/** - * Created by Bryn on 9/12/2018. - */ -public class AnyInCodeSystemInvocation extends OperatorExpressionInvocation { - public AnyInCodeSystemInvocation(AnyInCodeSystem expression) { - super(expression); - } - - @Override - public List getOperands() { - List result = new ArrayList<>(); - result.add(expression.getCodes()); - if (expression.getCodesystemExpression() != null) { - result.add(expression.getCodesystemExpression()); - } - return result; - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(!operands.isEmpty() && operands.size() <= 2, "AnyInCodeSystem operator requires one or two operands."); - - expression.setCodes(operands.get(0)); - if (operands.size() > 1) { - expression.setCodesystemExpression(operands.get(1)); - } - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AnyInCodeSystemInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AnyInCodeSystemInvocation.kt new file mode 100644 index 000000000..0a013bba5 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AnyInCodeSystemInvocation.kt @@ -0,0 +1,20 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.AnyInCodeSystem +import org.hl7.elm.r1.Expression + +/** Created by Bryn on 9/12/2018. */ +class AnyInCodeSystemInvocation(expression: AnyInCodeSystem) : + OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOfNotNull(expression.codes, expression.codesystemExpression) + set(operands) { + require(operands.size in 1..2) { + "AnyInCodeSystem operator requires one or two operands." + } + expression.codes = operands[0] + if (operands.size > 1) { + expression.codesystemExpression = operands[1] + } + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AnyInValueSetInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AnyInValueSetInvocation.java deleted file mode 100644 index c857cb3e2..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AnyInValueSetInvocation.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.ArrayList; -import java.util.List; -import org.hl7.elm.r1.AnyInValueSet; -import org.hl7.elm.r1.Expression; - -/** - * Created by Bryn on 9/12/2018. - */ -public class AnyInValueSetInvocation extends OperatorExpressionInvocation { - public AnyInValueSetInvocation(AnyInValueSet expression) { - super(expression); - } - - @Override - public List getOperands() { - List result = new ArrayList<>(); - result.add(expression.getCodes()); - if (expression.getValuesetExpression() != null) { - result.add(expression.getValuesetExpression()); - } - return result; - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(!operands.isEmpty() && operands.size() <= 2, "AnyInValueSet operator requires one or two operands."); - - expression.setCodes(operands.get(0)); - if (operands.size() > 1) { - expression.setValuesetExpression(operands.get(1)); - } - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AnyInValueSetInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AnyInValueSetInvocation.kt new file mode 100644 index 000000000..df9e5d374 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/AnyInValueSetInvocation.kt @@ -0,0 +1,20 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.AnyInValueSet +import org.hl7.elm.r1.Expression + +/** Created by Bryn on 9/12/2018. */ +class AnyInValueSetInvocation(expression: AnyInValueSet) : + OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOfNotNull(expression.codes, expression.valuesetExpression) + set(operands) { + require(operands.size in 1..2) { + "AnyInValueSet operator requires one or two operands." + } + expression.codes = operands[0] + if (operands.size > 1) { + expression.valuesetExpression = operands[1] + } + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/BinaryExpressionInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/BinaryExpressionInvocation.java deleted file mode 100644 index 5e1591e0d..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/BinaryExpressionInvocation.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.List; -import org.hl7.elm.r1.BinaryExpression; -import org.hl7.elm.r1.Expression; - -public class BinaryExpressionInvocation extends OperatorExpressionInvocation { - public BinaryExpressionInvocation(B expression) { - super(expression); - } - - @Override - public List getOperands() { - return expression.getOperand(); - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(operands.size() == 2, "BinaryExpression requires two operands."); - expression.setOperand(operands); - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/BinaryExpressionInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/BinaryExpressionInvocation.kt new file mode 100644 index 000000000..eb6ebd7f5 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/BinaryExpressionInvocation.kt @@ -0,0 +1,14 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.BinaryExpression +import org.hl7.elm.r1.Expression + +class BinaryExpressionInvocation(expression: B) : + OperatorExpressionInvocation(expression) { + override var operands: List + get() = expression.operand + set(operands) { + require(operands.size == 2) { "BinaryExpression requires two operands." } + expression.operand = operands + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/CombineInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/CombineInvocation.java deleted file mode 100644 index 85e97b71c..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/CombineInvocation.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.ArrayList; -import java.util.List; -import org.hl7.elm.r1.Combine; -import org.hl7.elm.r1.Expression; - -public class CombineInvocation extends OperatorExpressionInvocation { - public CombineInvocation(Combine expression) { - super(expression); - } - - @Override - public List getOperands() { - Combine combine = expression; - ArrayList ops = new ArrayList<>(); - ops.add(combine.getSource()); - if (combine.getSeparator() != null) { - ops.add(combine.getSeparator()); - } - return ops; - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(!operands.isEmpty() && operands.size() <= 2, "Combine operator requires one or two operands."); - - expression.setSource(operands.get(0)); - if (operands.size() > 1) { - expression.setSeparator(operands.get(1)); - } - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/CombineInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/CombineInvocation.kt new file mode 100644 index 000000000..9ccf08c00 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/CombineInvocation.kt @@ -0,0 +1,17 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Combine +import org.hl7.elm.r1.Expression + +class CombineInvocation(expression: Combine) : OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOfNotNull(expression.source, expression.separator) + set(operands) { + require(operands.size in 1..2) { "Combine operator requires one or two operands." } + + expression.source = operands[0] + if (operands.size > 1) { + expression.separator = operands[1] + } + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/ConvertInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/ConvertInvocation.java deleted file mode 100644 index 463597985..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/ConvertInvocation.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import java.util.Collections; -import java.util.List; -import org.hl7.elm.r1.Convert; -import org.hl7.elm.r1.Expression; - -public class ConvertInvocation extends OperatorExpressionInvocation { - public ConvertInvocation(Convert expression) { - super(expression); - } - - @Override - public List getOperands() { - return Collections.singletonList(expression.getOperand()); - } - - @Override - public void setOperands(List operands) { - expression.setOperand(requireSingleton(operands)); - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/ConvertInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/ConvertInvocation.kt new file mode 100644 index 000000000..590462ada --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/ConvertInvocation.kt @@ -0,0 +1,13 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Convert +import org.hl7.elm.r1.Expression + +class ConvertInvocation(expression: Convert) : OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOf(expression.operand) + set(operands) { + require(operands.size == 1) { "Unary operator expected." } + expression.operand = operands[0] + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/DateInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/DateInvocation.java deleted file mode 100644 index e5796b17d..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/DateInvocation.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.Arrays; -import java.util.List; -import org.hl7.elm.r1.Date; -import org.hl7.elm.r1.Expression; - -public class DateInvocation extends OperatorExpressionInvocation { - public DateInvocation(Date expression) { - super(expression); - } - - @Override - public List getOperands() { - Date dt = expression; - List opList = Arrays.asList(dt.getYear(), dt.getMonth(), dt.getDay()); - // If the last expression is null, we should trim this down - int i; - for (i = 2; i > 0 && opList.get(i) == null; i--) - ; - return opList.subList(0, i + 1); - } - - @Override - public void setOperands(List operands) { - setDateFieldsFromOperands(expression, operands); - } - - public static void setDateFieldsFromOperands(Date dt, List operands) { - requireNonNull(operands, "operands cannot be null."); - require(!operands.isEmpty() && operands.size() <= 3, "Date operator requires one to three operands."); - - dt.setYear(operands.get(0)); - if (operands.size() > 1) { - dt.setMonth(operands.get(1)); - } - if (operands.size() > 2) { - dt.setDay(operands.get(2)); - } - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/DateInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/DateInvocation.kt new file mode 100644 index 000000000..ef17e40ad --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/DateInvocation.kt @@ -0,0 +1,27 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Date +import org.hl7.elm.r1.Expression + +class DateInvocation(expression: Date) : OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOfNotNull(expression.year, expression.month, expression.day) + set(operands) { + setDateFieldsFromOperands(expression, operands) + } + + @Suppress("MagicNumber") + companion object { + @JvmStatic + fun setDateFieldsFromOperands(dt: Date, operands: List) { + require(operands.size in 1..3) { "Date operator requires one to three operands." } + dt.year = operands[0] + if (operands.size > 1) { + dt.month = operands[1] + } + if (operands.size > 2) { + dt.day = operands[2] + } + } + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/DateTimeInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/DateTimeInvocation.java deleted file mode 100644 index b29a5fc47..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/DateTimeInvocation.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.Arrays; -import java.util.List; -import org.hl7.elm.r1.DateTime; -import org.hl7.elm.r1.Expression; - -public class DateTimeInvocation extends OperatorExpressionInvocation { - public DateTimeInvocation(DateTime expression) { - super(expression); - } - - @Override - public List getOperands() { - DateTime dt = expression; - List opList = Arrays.asList( - dt.getYear(), - dt.getMonth(), - dt.getDay(), - dt.getHour(), - dt.getMinute(), - dt.getSecond(), - dt.getMillisecond(), - dt.getTimezoneOffset()); - // If the last expression is null, we should trim this down - int i; - for (i = 7; i > 0 && opList.get(i) == null; i--) - ; - return opList.subList(0, i + 1); - } - - @Override - public void setOperands(List operands) { - setDateTimeFieldsFromOperands(expression, operands); - } - - public static void setDateTimeFieldsFromOperands(DateTime dt, List operands) { - requireNonNull(operands, "operands cannot be null."); - require(!operands.isEmpty() && operands.size() <= 8, "DateTime operator requires one to eight operands."); - - dt.setYear(operands.get(0)); - if (operands.size() > 1) { - dt.setMonth(operands.get(1)); - } - if (operands.size() > 2) { - dt.setDay(operands.get(2)); - } - if (operands.size() > 3) { - dt.setHour(operands.get(3)); - } - if (operands.size() > 4) { - dt.setMinute(operands.get(4)); - } - if (operands.size() > 5) { - dt.setSecond(operands.get(5)); - } - if (operands.size() > 6) { - dt.setMillisecond(operands.get(6)); - } - if (operands.size() > 7) { - dt.setTimezoneOffset(operands.get(7)); - } - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/DateTimeInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/DateTimeInvocation.kt new file mode 100644 index 000000000..1808460f1 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/DateTimeInvocation.kt @@ -0,0 +1,54 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.DateTime +import org.hl7.elm.r1.Expression + +class DateTimeInvocation(expression: DateTime) : + OperatorExpressionInvocation(expression) { + override var operands: List + get() = + listOfNotNull( + expression.year, + expression.month, + expression.day, + expression.hour, + expression.minute, + expression.second, + expression.millisecond, + expression.timezoneOffset + ) + set(operands) { + setDateTimeFieldsFromOperands(expression, operands) + } + + @Suppress("MagicNumber") + companion object { + @JvmStatic + fun setDateTimeFieldsFromOperands(dt: DateTime, operands: List) { + require(operands.size in 1..8) { "DateTime operator requires one to eight operands." } + + dt.year = operands[0] + if (operands.size > 1) { + dt.month = operands[1] + } + if (operands.size > 2) { + dt.day = operands[2] + } + if (operands.size > 3) { + dt.hour = operands[3] + } + if (operands.size > 4) { + dt.minute = operands[4] + } + if (operands.size > 5) { + dt.second = operands[5] + } + if (operands.size > 6) { + dt.millisecond = operands[6] + } + if (operands.size > 7) { + dt.timezoneOffset = operands[7] + } + } + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/FirstInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/FirstInvocation.java deleted file mode 100644 index 0ac6eb12b..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/FirstInvocation.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import java.util.Collections; -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.First; - -public class FirstInvocation extends OperatorExpressionInvocation { - public FirstInvocation(First expression) { - super(expression); - } - - @Override - public List getOperands() { - return Collections.singletonList(expression.getSource()); - } - - @Override - public void setOperands(List operands) { - expression.setSource(requireSingleton(operands)); - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/FirstInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/FirstInvocation.kt new file mode 100644 index 000000000..687525ae6 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/FirstInvocation.kt @@ -0,0 +1,13 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.First + +class FirstInvocation(expression: First) : OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOf(expression.source) + set(operands) { + require(operands.size == 1) { "Unary operator expected." } + expression.source = operands[0] + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/FunctionRefInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/FunctionRefInvocation.java deleted file mode 100644 index 888e0989c..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/FunctionRefInvocation.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.List; -import org.cqframework.cql.cql2elm.model.OperatorResolution; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.FunctionRef; -import org.hl7.elm.r1.TypeSpecifier; - -public class FunctionRefInvocation extends AbstractExpressionInvocation { - public FunctionRefInvocation(FunctionRef expression) { - super(expression); - } - - @Override - public List getOperands() { - return expression.getOperand(); - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - expression.setOperand(operands); - } - - @Override - public List getSignature() { - return expression.getSignature(); - } - - @Override - public void setSignature(List signature) { - for (TypeSpecifier typeSpecifier : signature) { - expression.getSignature().add(typeSpecifier); - } - } - - @Override - public void setResolution(OperatorResolution resolution) { - super.setResolution(resolution); - FunctionRef fr = expression; - if (resolution.getLibraryName() != null && !resolution.getLibraryName().equals(fr.getLibraryName())) { - fr.setLibraryName(resolution.getLibraryName()); - } - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/FunctionRefInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/FunctionRefInvocation.kt new file mode 100644 index 000000000..da7c687d9 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/FunctionRefInvocation.kt @@ -0,0 +1,30 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.cqframework.cql.cql2elm.model.OperatorResolution +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.FunctionRef +import org.hl7.elm.r1.TypeSpecifier + +class FunctionRefInvocation(expression: FunctionRef) : + AbstractExpressionInvocation(expression) { + override var operands: List + get() = expression.operand + set(operands) { + expression.operand = operands + } + + override var signature: List + get() = expression.signature + set(signature) { + expression.signature = signature + } + + override var resolution: OperatorResolution? + get() = super.resolution + set(resolution) { + super.resolution = resolution + if (resolution?.libraryName != expression.libraryName) { + expression.libraryName = resolution?.libraryName + } + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/InCodeSystemInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/InCodeSystemInvocation.java deleted file mode 100644 index 468b742f1..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/InCodeSystemInvocation.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.ArrayList; -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.InCodeSystem; - -public class InCodeSystemInvocation extends OperatorExpressionInvocation { - public InCodeSystemInvocation(InCodeSystem expression) { - super(expression); - } - - @Override - public List getOperands() { - List result = new ArrayList<>(); - result.add(expression.getCode()); - if (expression.getCodesystemExpression() != null) { - result.add(expression.getCodesystemExpression()); - } - return result; - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(!operands.isEmpty() && operands.size() <= 2, "InCodeSystem operator requires one or two operands."); - - expression.setCode(operands.get(0)); - if (operands.size() > 1) { - expression.setCodesystemExpression(operands.get(1)); - } - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/InCodeSystemInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/InCodeSystemInvocation.kt new file mode 100644 index 000000000..c10a814c9 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/InCodeSystemInvocation.kt @@ -0,0 +1,18 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.InCodeSystem + +class InCodeSystemInvocation(expression: InCodeSystem) : + OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOfNotNull(expression.code, expression.codesystemExpression) + set(operands) { + require(operands.size in 1..2) { "InCodeSystem operator requires one or two operands." } + + expression.code = operands[0] + if (operands.size > 1) { + expression.codesystemExpression = operands[1] + } + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/InValueSetInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/InValueSetInvocation.java deleted file mode 100644 index 6d8dad3a9..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/InValueSetInvocation.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.ArrayList; -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.InValueSet; - -public class InValueSetInvocation extends OperatorExpressionInvocation { - public InValueSetInvocation(InValueSet expression) { - super(expression); - } - - @Override - public List getOperands() { - List result = new ArrayList<>(); - result.add(expression.getCode()); - if (expression.getValuesetExpression() != null) { - result.add(expression.getValuesetExpression()); - } - return result; - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(!operands.isEmpty() && operands.size() <= 2, "InValueSet operator requires one or two operands."); - expression.setCode(operands.get(0)); - if (operands.size() > 1) { - expression.setValuesetExpression(operands.get(1)); - } - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/InValueSetInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/InValueSetInvocation.kt new file mode 100644 index 000000000..e7e2e105e --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/InValueSetInvocation.kt @@ -0,0 +1,17 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.InValueSet + +class InValueSetInvocation(expression: InValueSet) : + OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOfNotNull(expression.code, expression.valuesetExpression) + set(operands) { + require(operands.size in 1..2) { "InValueSet operator requires one or two operands." } + expression.code = operands[0] + if (operands.size > 1) { + expression.valuesetExpression = operands[1] + } + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/IndexOfInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/IndexOfInvocation.java deleted file mode 100644 index 9679e8870..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/IndexOfInvocation.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.Arrays; -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.IndexOf; - -public class IndexOfInvocation extends OperatorExpressionInvocation { - public IndexOfInvocation(IndexOf expression) { - super(expression); - } - - @Override - public List getOperands() { - return Arrays.asList(expression.getSource(), expression.getElement()); - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(operands.size() == 2, "IndexOf operator requires two operands."); - - expression.setSource(operands.get(0)); - expression.setElement(operands.get(1)); - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/IndexOfInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/IndexOfInvocation.kt new file mode 100644 index 000000000..9d8f39f0a --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/IndexOfInvocation.kt @@ -0,0 +1,14 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.IndexOf + +class IndexOfInvocation(expression: IndexOf) : OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOfNotNull(expression.source, expression.element) + set(operands) { + require(operands.size == 2) { "IndexOf operator requires two operands." } + expression.source = operands[0] + expression.element = operands[1] + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/LastInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/LastInvocation.java deleted file mode 100644 index 9c79aa48c..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/LastInvocation.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import java.util.Collections; -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.Last; - -public class LastInvocation extends OperatorExpressionInvocation { - public LastInvocation(Last expression) { - super(expression); - } - - @Override - public List getOperands() { - return Collections.singletonList(expression.getSource()); - } - - @Override - public void setOperands(List operands) { - expression.setSource(requireSingleton(operands)); - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/LastInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/LastInvocation.kt new file mode 100644 index 000000000..8dc111dfe --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/LastInvocation.kt @@ -0,0 +1,13 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.Last + +class LastInvocation(expression: Last) : OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOf(expression.source) + set(operands) { + require(operands.size == 1) { "Unary operator expected." } + expression.source = operands[0] + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/LastPositionOfInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/LastPositionOfInvocation.java deleted file mode 100644 index c40b54c43..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/LastPositionOfInvocation.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.Arrays; -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.LastPositionOf; - -public class LastPositionOfInvocation extends OperatorExpressionInvocation { - public LastPositionOfInvocation(LastPositionOf expression) { - super(expression); - } - - @Override - public List getOperands() { - return Arrays.asList(expression.getPattern(), expression.getString()); - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(operands.size() == 2, "LastPositionOf operator requires two operands."); - expression.setPattern(operands.get(0)); - expression.setString(operands.get(1)); - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/LastPositionOfInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/LastPositionOfInvocation.kt new file mode 100644 index 000000000..e99d86174 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/LastPositionOfInvocation.kt @@ -0,0 +1,15 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.LastPositionOf + +class LastPositionOfInvocation(expression: LastPositionOf) : + OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOf(expression.pattern, expression.string) + set(operands) { + require(operands.size == 2) { "LastPositionOf operator requires two operands." } + expression.pattern = operands[0] + expression.string = operands[1] + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/MessageInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/MessageInvocation.java deleted file mode 100644 index 0c68b508d..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/MessageInvocation.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.Arrays; -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.Message; - -public class MessageInvocation extends OperatorExpressionInvocation { - public MessageInvocation(Message expression) { - super(expression); - } - - @Override - public List getOperands() { - return Arrays.asList( - expression.getSource(), - expression.getCondition(), - expression.getCode(), - expression.getSeverity(), - expression.getMessage()); - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(operands.size() == 5, "Message operator requires five operands."); - expression.setSource(operands.get(0)); - expression.setCondition(operands.get(1)); - expression.setCode(operands.get(2)); - expression.setSeverity(operands.get(3)); - expression.setMessage(operands.get(4)); - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/MessageInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/MessageInvocation.kt new file mode 100644 index 000000000..cb77f6a61 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/MessageInvocation.kt @@ -0,0 +1,25 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.Message + +class MessageInvocation(expression: Message) : OperatorExpressionInvocation(expression) { + override var operands: List + get() = + listOf( + expression.source, + expression.condition, + expression.code, + expression.severity, + expression.message + ) + @Suppress("MagicNumber") + set(operands) { + require(operands.size == 5) { "Message operator requires five operands." } + expression.source = operands[0] + expression.condition = operands[1] + expression.code = operands[2] + expression.severity = operands[3] + expression.message = operands[4] + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/NaryExpressionInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/NaryExpressionInvocation.java deleted file mode 100644 index c3c50e7de..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/NaryExpressionInvocation.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.NaryExpression; - -public class NaryExpressionInvocation extends OperatorExpressionInvocation { - public NaryExpressionInvocation(NaryExpression expression) { - super(expression); - } - - @Override - public List getOperands() { - return expression.getOperand(); - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - expression.setOperand(operands); - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/NaryExpressionInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/NaryExpressionInvocation.kt new file mode 100644 index 000000000..3c0730068 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/NaryExpressionInvocation.kt @@ -0,0 +1,13 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.NaryExpression + +class NaryExpressionInvocation(expression: NaryExpression) : + OperatorExpressionInvocation(expression) { + override var operands: List + get() = expression.operand + set(operands) { + expression.operand = operands + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/OperatorExpressionInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/OperatorExpressionInvocation.java deleted file mode 100644 index 6199f96da..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/OperatorExpressionInvocation.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import java.util.List; -import org.hl7.elm.r1.OperatorExpression; -import org.hl7.elm.r1.TypeSpecifier; - -/** - * Created by Bryn on 4/12/2018. - */ -@SuppressWarnings("checkstyle:abstractclassname") -public abstract class OperatorExpressionInvocation - extends AbstractExpressionInvocation { - protected OperatorExpressionInvocation(O expression) { - super(expression); - } - - @Override - public List getSignature() { - return expression.getSignature(); - } - - @Override - public void setSignature(List signature) { - for (TypeSpecifier typeSpecifier : signature) { - expression.getSignature().add(typeSpecifier); - } - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/OperatorExpressionInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/OperatorExpressionInvocation.kt new file mode 100644 index 000000000..1de6f3611 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/OperatorExpressionInvocation.kt @@ -0,0 +1,14 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.OperatorExpression +import org.hl7.elm.r1.TypeSpecifier + +/** Created by Bryn on 4/12/2018. */ +abstract class OperatorExpressionInvocation(expression: O) : + AbstractExpressionInvocation(expression) { + override var signature: List<@JvmSuppressWildcards TypeSpecifier> + get() = expression.signature + set(signature) { + expression.signature = signature + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/PositionOfInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/PositionOfInvocation.java deleted file mode 100644 index d825e134b..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/PositionOfInvocation.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.Arrays; -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.PositionOf; - -public class PositionOfInvocation extends OperatorExpressionInvocation { - public PositionOfInvocation(PositionOf expression) { - super(expression); - } - - @Override - public List getOperands() { - return Arrays.asList(expression.getPattern(), expression.getString()); - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(operands.size() == 2, "PositionOf operator requires two operands."); - expression.setPattern(operands.get(0)); - expression.setString(operands.get(1)); - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/PositionOfInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/PositionOfInvocation.kt new file mode 100644 index 000000000..29fa47cc2 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/PositionOfInvocation.kt @@ -0,0 +1,15 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.PositionOf + +class PositionOfInvocation(expression: PositionOf) : + OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOf(expression.pattern, expression.string) + set(operands) { + require(operands.size == 2) { "PositionOf operator requires two operands." } + expression.pattern = operands[0] + expression.string = operands[1] + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/RoundInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/RoundInvocation.java deleted file mode 100644 index 06cf90c98..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/RoundInvocation.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.ArrayList; -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.Round; - -public class RoundInvocation extends OperatorExpressionInvocation { - public RoundInvocation(Round expression) { - super(expression); - } - - @Override - public List getOperands() { - var ops = new ArrayList(); - ops.add(expression.getOperand()); - if (expression.getPrecision() != null) { - ops.add(expression.getPrecision()); - } - return ops; - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(!operands.isEmpty() && operands.size() <= 2, "Round operator requires one or two operands."); - expression.setOperand(operands.get(0)); - if (operands.size() > 1) { - expression.setPrecision(operands.get(1)); - } - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/RoundInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/RoundInvocation.kt new file mode 100644 index 000000000..ce9d69e1f --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/RoundInvocation.kt @@ -0,0 +1,16 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.Round + +class RoundInvocation(expression: Round) : OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOfNotNull(expression.operand, expression.precision) + set(operands) { + require(operands.size in 1..2) { "Round operator requires one or two operands." } + expression.operand = operands[0] + if (operands.size > 1) { + expression.precision = operands[1] + } + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SkipInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SkipInvocation.java deleted file mode 100644 index e4fffd4c7..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SkipInvocation.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.Arrays; -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.Slice; - -/** - * Created by Bryn on 5/17/2017. - */ -public class SkipInvocation extends OperatorExpressionInvocation { - public SkipInvocation(Slice expression) { - super(expression); - } - - @Override - public List getOperands() { - return Arrays.asList(expression.getSource(), expression.getStartIndex()); - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(operands.size() == 2, "Skip operator requires two operands."); - - expression.setSource(operands.get(0)); - expression.setStartIndex(operands.get(1)); - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SkipInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SkipInvocation.kt new file mode 100644 index 000000000..2c8bc6471 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SkipInvocation.kt @@ -0,0 +1,16 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.Slice + +/** Created by Bryn on 5/17/2017. */ +class SkipInvocation(expression: Slice) : OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOf(expression.source, expression.startIndex) + set(operands) { + require(operands.size == 2) { "Skip operator requires two operands." } + + expression.source = operands[0] + expression.startIndex = operands[1] + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SplitInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SplitInvocation.java deleted file mode 100644 index d4a5ff0ae..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SplitInvocation.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.Arrays; -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.Split; - -public class SplitInvocation extends OperatorExpressionInvocation { - public SplitInvocation(Split expression) { - super(expression); - } - - @Override - public List getOperands() { - return Arrays.asList(expression.getStringToSplit(), expression.getSeparator()); - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(operands.size() == 2, "Split operator requires two operands."); - - expression.setStringToSplit(operands.get(0)); - expression.setSeparator(operands.get(1)); - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SplitInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SplitInvocation.kt new file mode 100644 index 000000000..dcac6c663 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SplitInvocation.kt @@ -0,0 +1,14 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.Split + +class SplitInvocation(expression: Split) : OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOf(expression.stringToSplit, expression.separator) + set(operands) { + require(operands.size == 2) { "Split operator requires two operands." } + expression.stringToSplit = operands[0] + expression.separator = operands[1] + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SplitOnMatchesInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SplitOnMatchesInvocation.java deleted file mode 100644 index 8c0201626..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SplitOnMatchesInvocation.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.Arrays; -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.SplitOnMatches; - -public class SplitOnMatchesInvocation extends OperatorExpressionInvocation { - public SplitOnMatchesInvocation(SplitOnMatches expression) { - super(expression); - } - - @Override - public List getOperands() { - return Arrays.asList(expression.getStringToSplit(), expression.getSeparatorPattern()); - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(operands.size() == 2, "SplitOnMatches operator requires two operands."); - - expression.setStringToSplit(operands.get(0)); - expression.setSeparatorPattern(operands.get(1)); - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SplitOnMatchesInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SplitOnMatchesInvocation.kt new file mode 100644 index 000000000..49aed8f12 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SplitOnMatchesInvocation.kt @@ -0,0 +1,15 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.SplitOnMatches + +class SplitOnMatchesInvocation(expression: SplitOnMatches) : + OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOf(expression.stringToSplit, expression.separatorPattern) + set(operands) { + require(operands.size == 2) { "SplitOnMatches operator requires two operands." } + expression.stringToSplit = operands[0] + expression.separatorPattern = operands[1] + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SubstringInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SubstringInvocation.java deleted file mode 100644 index d6e737ce0..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SubstringInvocation.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.ArrayList; -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.Substring; - -public class SubstringInvocation extends OperatorExpressionInvocation { - public SubstringInvocation(Substring expression) { - super(expression); - } - - @Override - public List getOperands() { - ArrayList ops = new ArrayList<>(); - ops.add(expression.getStringToSub()); - ops.add(expression.getStartIndex()); - if (expression.getLength() != null) { - ops.add(expression.getLength()); - } - return ops; - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(operands.size() >= 2 && operands.size() <= 3, "Substring operator requires two or three operands."); - - expression.setStringToSub(operands.get(0)); - expression.setStartIndex(operands.get(1)); - if (operands.size() > 2) { - expression.setLength(operands.get(2)); - } - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SubstringInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SubstringInvocation.kt new file mode 100644 index 000000000..87c34cc7e --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/SubstringInvocation.kt @@ -0,0 +1,19 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.Substring + +class SubstringInvocation(expression: Substring) : + OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOfNotNull(expression.stringToSub, expression.startIndex, expression.length) + @Suppress("MagicNumber") + set(operands) { + require(operands.size in 2..3) { "Substring operator requires two or three operands." } + expression.stringToSub = operands[0] + expression.startIndex = operands[1] + if (operands.size > 2) { + expression.length = operands[2] + } + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TailInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TailInvocation.java deleted file mode 100644 index 75fce3ec9..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TailInvocation.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import java.util.Collections; -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.Slice; - -/** - * Created by Bryn on 5/17/2017. - */ -public class TailInvocation extends OperatorExpressionInvocation { - public TailInvocation(Slice expression) { - super(expression); - } - - @Override - public List getOperands() { - return Collections.singletonList(expression.getSource()); - } - - @Override - public void setOperands(List operands) { - expression.setSource(requireSingleton(operands)); - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TailInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TailInvocation.kt new file mode 100644 index 000000000..ed2c69d5c --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TailInvocation.kt @@ -0,0 +1,14 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.Slice + +/** Created by Bryn on 5/17/2017. */ +class TailInvocation(expression: Slice) : OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOf(expression.source) + set(operands) { + require(operands.size == 1) { "Unary operator expected." } + expression.source = operands[0] + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TakeInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TakeInvocation.java deleted file mode 100644 index 6bff8c563..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TakeInvocation.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.Arrays; -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.Slice; - -/** - * Created by Bryn on 5/17/2017. - */ -public class TakeInvocation extends OperatorExpressionInvocation { - public TakeInvocation(Slice expression) { - super(expression); - } - - @Override - public List getOperands() { - return Arrays.asList(expression.getSource(), expression.getEndIndex()); - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - require(operands.size() == 2, "Take operator requires two operands."); - expression.setSource(operands.get(0)); - expression.setEndIndex(operands.get(1)); - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TakeInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TakeInvocation.kt new file mode 100644 index 000000000..c8f324d11 --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TakeInvocation.kt @@ -0,0 +1,15 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.Slice + +/** Created by Bryn on 5/17/2017. */ +class TakeInvocation(expression: Slice) : OperatorExpressionInvocation(expression) { + override var operands: List + get() = listOf(expression.source, expression.endIndex) + set(operands) { + require(operands.size == 2) { "Take operator requires two operands." } + expression.source = operands[0] + expression.endIndex = operands[1] + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TernaryExpressionInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TernaryExpressionInvocation.java deleted file mode 100644 index 7db849b87..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TernaryExpressionInvocation.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.TernaryExpression; - -public class TernaryExpressionInvocation extends OperatorExpressionInvocation { - public TernaryExpressionInvocation(T expression) { - super(expression); - } - - @Override - public List getOperands() { - return expression.getOperand(); - } - - @Override - public void setOperands(List operands) { - requireNonNull(operands, "operands cannot be null."); - expression.setOperand(operands); - } -} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TernaryExpressionInvocation.kt b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TernaryExpressionInvocation.kt new file mode 100644 index 000000000..1c308884d --- /dev/null +++ b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TernaryExpressionInvocation.kt @@ -0,0 +1,13 @@ +package org.cqframework.cql.cql2elm.model.invocation + +import org.hl7.elm.r1.Expression +import org.hl7.elm.r1.TernaryExpression + +class TernaryExpressionInvocation(expression: T) : + OperatorExpressionInvocation(expression) { + override var operands: List + get() = expression.operand + set(operands) { + expression.operand = operands + } +} diff --git a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TimeInvocation.java b/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TimeInvocation.java deleted file mode 100644 index 27d692c84..000000000 --- a/Src/java/cql-to-elm/src/main/java/org/cqframework/cql/cql2elm/model/invocation/TimeInvocation.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.cqframework.cql.cql2elm.model.invocation; - -import static java.util.Objects.requireNonNull; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import org.hl7.elm.r1.Expression; -import org.hl7.elm.r1.Time; - -public class TimeInvocation extends OperatorExpressionInvocation