Skip to content

Commit

Permalink
Merge branch 'master' into proper-in-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
antvaset authored Aug 1, 2024
2 parents 03db5ab + 7e91478 commit 9e6e470
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ public Invocation resolveSystemFunction(FunctionRef fun) {
case "ToTime":
case "ToQuantity":
case "ToRatio":
case "ToConcept": {
case "ToConcept":
case "ToChars": {
return resolveUnary(fun);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ public static Object[][] dataMethod() {
"cql/CqlIntervalOperatorsTest/Expand/ExpandPer1",
"cql/CqlIntervalOperatorsTest/Expand/ExpandPer2Days",
"cql/CqlIntervalOperatorsTest/Expand/ExpandPerMinute",
"cql/CqlListOperatorsTest/Distinct/DistinctANullANull",
"cql/CqlListOperatorsTest/Distinct/DistinctNullNullNull",
"cql/CqlListOperatorsTest/Equivalent/Equivalent123AndABC",
"cql/CqlListOperatorsTest/Equivalent/Equivalent123AndString123",
"cql/CqlListOperatorsTest/Equivalent/EquivalentABCAnd123",
Expand Down Expand Up @@ -176,10 +174,6 @@ public static Object[][] dataMethod() {
"r4/tests-fhir-r4/testIif/testIif3",
"r4/tests-fhir-r4/testIif/testIif4",
"r4/tests-fhir-r4/testIndexer/testIndexer1",
"r4/tests-fhir-r4/testIntersect/testIntersect1",
"r4/tests-fhir-r4/testIntersect/testIntersect2",
"r4/tests-fhir-r4/testIntersect/testIntersect3",
"r4/tests-fhir-r4/testIntersect/testIntersect4",
"r4/tests-fhir-r4/testInvariants/extension('http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-scoring').exists() and extension('http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-scoring').value = 'ratio' implies group.population.where(code.coding.where(system = 'http://terminology.hl7.org/CodeSystem/measure-population').code = 'initial-population').count() in (1 | 2)",
"r4/tests-fhir-r4/testLessOrEqual/testLessOrEqual26",
"r4/tests-fhir-r4/testLessOrEqual/testLessOrEqual27",
Expand Down Expand Up @@ -240,9 +234,6 @@ public static Object[][] dataMethod() {
"r4/tests-fhir-r4/testTake/testTake4",
"r4/tests-fhir-r4/testTimeOfDay/testTimeOfDay1",
"r4/tests-fhir-r4/testToChars/testToChars1",
"r4/tests-fhir-r4/testToday/testToday1",
"r4/tests-fhir-r4/testToday/testToday2",
"r4/tests-fhir-r4/testToday/testToday3",
"r4/tests-fhir-r4/testToInteger/testToInteger4",
"r4/tests-fhir-r4/testTrace/testTrace2",
"r4/tests-fhir-r4/testType/testType1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@
<output>false</output>
</test>
</group>
<group name="ToChars">
<test name="StringToChars">
<expression>ToChars('abc123')</expression>
<output>{ 'a', 'b', 'c', '1', '2', '3' }</output>
</test>
<test name="EmptyStringToChars">
<expression>ToChars('')</expression>
<output>{}</output>
</test>
<test name="NullToChars">
<expression>ToChars(null)</expression>
<output>null</output>
</test>
<test name="ToCharsMalformed">
<expression invalid="true">ToChars(123)</expression>
</test>
</group>
<group name="ToConcept">
<test name="CodeToConcept1">
<expression>ToConcept(Code { code: '8480-6' })</expression>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.opencds.cqf.cql.engine.elm.executing;

import java.util.ArrayList;
import java.util.List;
import org.opencds.cqf.cql.engine.exception.InvalidOperatorArgument;

/*
ToChars(argument String) List<String>
The ToChars operator takes a string and returns a list with one string for each character in the input, in the order in which they appear in the string.
If the argument is null, the result is null.
*/

public class ToCharsEvaluator {

public static List<String> toChars(Object operand) {
if (operand == null) {
return null;
}

if (operand instanceof String) {
List<String> result = new ArrayList<>();
for (char c : ((String) operand).toCharArray()) {
result.add(String.valueOf(c));
}
return result;
}

throw new InvalidOperatorArgument(
"ToChars(String)",
String.format("ToInteger(%s)", operand.getClass().getName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ public Object visitToConcept(ToConcept elm, State state) {
return ToConceptEvaluator.toConcept(operand);
}

@Override
public Object visitToChars(ToChars elm, State state) {
Object operand = visitExpression(elm.getOperand(), state);
return ToCharsEvaluator.toChars(operand);
}

@Override
public Object visitToDate(ToDate elm, State state) {
Object operand = visitExpression(elm.getOperand(), state);
Expand Down

0 comments on commit 9e6e470

Please sign in to comment.