Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@
<expression>10.0 'g' / 5</expression>
<output>2.0'g'</output>
</test>
<test name="Divide10Q0I">
<expression>10.0 'g' / 0</expression>
<output>null</output>
</test>
</group>
<group name="Floor">
<test name="FloorNull">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
<expression>1'cm':2'cm' = 1.1'cm':2'cm'</expression>
<output>false</output>
</test>
<test name="RatioNotEqual2">
<expression>1'cm':2'cm' = 2'cm':4'cm'</expression>
<output>false</output>
</test>
<test name="TupleEqJohnJohn">
<expression>Tuple { Id : 1, Name : 'John' } = Tuple { Id : 1, Name : 'John' }</expression>
<output>true</output>
Expand Down Expand Up @@ -722,6 +726,14 @@
<expression>1'cm':2'cm' ~ 1'cm':2'cm'</expression>
<output>true</output>
</test>
<test name="RatioEquivalent2">
<expression>1'cm':2'cm' ~ 2'cm':4'cm'</expression>
<output>true</output>
</test>
<test name="RatioEquivalent3">
<expression>1'cm':0'cm' ~ 2'cm':0'cm'</expression>
<output>true</output>
</test>
<test name="RatioNotEquivalent">
<expression>1'cm':2'cm' ~ 1'cm':3'cm'</expression>
<output>false</output>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@ public static Object divide(Object left, Object right, State state) {
return divideHelper((BigDecimal) left, (BigDecimal) right, state);
} else if (left instanceof Quantity && right instanceof Quantity) {
BigDecimal value = divideHelper(((Quantity) left).getValue(), ((Quantity) right).getValue(), state);
return new Quantity().withValue(Value.verifyPrecision(value, null)).withUnit(((Quantity) left).getUnit());
if (value == null) {
return null;
}
return new Quantity().withValue(value).withUnit(((Quantity) left).getUnit());
} else if (left instanceof Quantity && right instanceof BigDecimal) {
BigDecimal value = divideHelper(((Quantity) left).getValue(), (BigDecimal) right, state);
return new Quantity().withValue(Value.verifyPrecision(value, null)).withUnit(((Quantity) left).getUnit());
if (value == null) {
return null;
}
return new Quantity().withValue(value).withUnit(((Quantity) left).getUnit());
} else if (left instanceof Interval && right instanceof Interval) {
Interval leftInterval = (Interval) left;
Interval rightInterval = (Interval) right;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.opencds.cqf.cql.engine.elm.executing.EqualEvaluator;
import org.opencds.cqf.cql.engine.elm.executing.EquivalentEvaluator;
import org.opencds.cqf.cql.engine.elm.executing.MultiplyEvaluator;

public class Ratio implements CqlType {

Expand All @@ -26,10 +27,15 @@ public Ratio setDenominator(Quantity denominator) {
return this;
}

/**
* For ratios, equivalent means that the numerator and denominator represent the same ratio (e.g. 1:100 ~ 10:1000).
*/
@Override
public Boolean equivalent(Object other) {
return EquivalentEvaluator.equivalent(this.getNumerator(), ((Ratio) other).getNumerator())
&& EquivalentEvaluator.equivalent(this.getDenominator(), ((Ratio) other).getDenominator());
var otherRatio = (Ratio) other;
return EquivalentEvaluator.equivalent(
MultiplyEvaluator.multiply(this.getNumerator(), otherRatio.getDenominator()),
MultiplyEvaluator.multiply(otherRatio.getNumerator(), this.getDenominator()));
}

@Override
Expand Down
Loading