Equivalent returns null for Quantities with incompatible units
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript
- Domain
- backend
Research direction
The bug is in equivalent in src/util/comparison.ts, which returns a.equals(b) for Quantities, so the null from Equal leaks through. Start by reading that function and how Ratio.equivalent already maps null to false. Done when 3.5 'cm2' ~ 3.5 'cm' returns false and a test covering incompatible units passes.
Written by the indexing model from the issue text.
Description
Summary
Equivalent (1.5.3 and 2.0):
The equivalent (~) operator returns true if the arguments are equivalent in value, or if they are both null; and false otherwise.
For Quantities: "Note that implementations are not required to support unit conversion and so are allowed to return false for equivalence of quantities with different units." The spec's example is define "QuantityEquivalentIsFalse": 3.5 'cm2' ~ 3.5 'cm'.
| Expression | cql-execution | Spec | Java engine 5.8.0 |
|---|---|---|---|
3.5 'cm2' ~ 3.5 'cm' |
null |
false |
false |
1 'g' ~ 1 'm' |
null |
false |
Cause
equivalent (src/util/comparison.ts) returns a.equals(b) for Quantities ("Quantity equivalence is the same as Quantity equality"), so the null that Equal gives for units that can't be compared comes through. A null from equals should become false, as Ratio.equivalent already does.
Environment
cql-execution master e8096c6, through test-server (the build has two unrelated Quantity modulo commits on top). The Java engine column is HAPI FHIR 9.0.0 with clinical-reasoning 4.17.0, through $cql.
- Dominant language
- JavaScript
- Stars
- 86
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cqframework/cql-execution
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
cqframework/cql-execution#407 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
cqframework/cql-execution#406 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
cqframework/cql-execution#414 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
cqframework/cql-execution#413 ·
-
Length throws TypeError when its null operand is not an As expression (e.g. an expression reference)Open
Difficulty 3/5 1-2 days Newbie friendliness 65/100
cqframework/cql-execution#412 ·
All issues in cqframework/cql-execution
Similar issues
-
Mend: dependency security vulnerability
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
ManageIQ/manageiq-ui-service#2259 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
sagemathinc/sagebrush-agent#230 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
electerious/Ackee#411 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
babalae/bettergi-scripts-list#3905 · 1 comment ·
Maintainers usually reply within 1 day