Equivalent returns null for Quantities with incompatible units

Open Beginner friendly
#410 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cqframework/cql-execution

All issues in cqframework/cql-execution

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.