Ratio Equal compares the quotient instead of the numerator and denominator

Open Beginner friendly
#406 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
62/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript
Domain
backend

Research direction

The bug is in Ratio.equals in src/datatypes/ratio.ts, which divides numerator by denominator and compares quotients; equivalent calls it and should keep the quotient comparison. Start by reading those two methods and the Quantity equality helper they should use for numerator and denominator. Done when 1:8 = 2:16 returns false, 1:8 != 2:16 returns true, and 1:8 ~ 2:16 stays true, confirmed by adding tests next to the existing ratio tests.

Written by the indexing model from the issue text.

Description

Summary

1:8 = 2:16 is true, but Equal (1.5.3 and 2.0) says:

For ratios, this means that the numerator and denominator must be the same, using quantity equality semantics.

The spec's own example is define "RatioEqualIsFalse": 1:8 = 2:16. Comparing the quotients is what Equivalent specifies: "For ratios, equivalent means that the numerator and denominator represent the same ratio (e.g. 1:100 ~ 10:1000)".

Expression cql-execution Spec Java engine 5.8.0
1:8 = 2:16 true false false
1:8 != 2:16 false true true
1:8 = 1:8 true true true
1:8 ~ 2:16 true true true

Cause

Ratio.equals (src/datatypes/ratio.ts) divides each numerator by its denominator and compares the results, and Ratio.equivalent calls equals. equals should compare numerator with numerator and denominator with denominator, using Quantity equality. equivalent keeps the quotient comparison.

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.