Skip to content

Fix a typo in the quantity tests#243

Open
jingtang10 wants to merge 1 commit into
FHIR:masterfrom
jingtang10:testQuantity4
Open

Fix a typo in the quantity tests#243
jingtang10 wants to merge 1 commit into
FHIR:masterfrom
jingtang10:testQuantity4

Conversation

@jingtang10
Copy link
Copy Markdown
Contributor

@jingtang10 jingtang10 commented Oct 7, 2025

My guess is that intention of the first 4 test cases for quantity is to test =, ~, !=, and !~ operators in order. So I corrected testQuantity4 to test !~ instead of using ~.

@jingtang10
Copy link
Copy Markdown
Contributor Author

I want to add that different FHIRPath engines implement this differently:

fhirpath-lab

This is surprising to me since the spec states very clearly:

When comparing quantities for equality, the dimensions of each quantity must be the same, but not necessarily the unit ... The comparison will be made using the most granular unit of either input.

Copy link
Copy Markdown
Member

@brynrhodes brynrhodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note sure on this one, since the equivalent for decimals says precision is ignored, but if you perform the conversion as specified in Quantity, the conversion to mg would be performed first, resulting in a comparison of 4000 to 4040, so shouldn't this be not equivalent?

https://hl7.org/fhirpath/#equivalent

@jingtang10
Copy link
Copy Markdown
Contributor Author

Bryn and I discussed this one and we think the spec is not clear.

In the quantity equivalence section, there's this sentence:

The comparison will be made using the most granular unit of either input.

So that is to indicate the quantities in question should be converted to mg before comparison.

Then, how is equivalence actually determined? There is no mention in the spec, it should say that the the numeric parts of the quantities should be equivalent following the decimal equivalence definition - which includes this sentence: comparison is done on values rounded to the precision of the least precise operand.

Now there is a question whether the precision is preserved after converting 4g to 4000mg. So although the value here is 4000mg, since the precision is only the first significant digit (actually i don't know if this is valid since it's not expressed in scientific notation, but let's assume this is expressed in scientific notation.) comparing it with 4040 mg still would result in equivalence.

But if this is true, this sentence: The comparison will be made using the most granular unit of either input. would never be useful?... since we might as well just use the least granular unit of the inputs?

Moreover, Bryn raised his concern that this is actually stepping on the toes of UCUM.

Copy link
Copy Markdown
Collaborator

@grahamegrieve grahamegrieve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@grahamegrieve
Copy link
Copy Markdown
Collaborator

Is there a jira task for the committee to clarify this?

@brianpos
Copy link
Copy Markdown
Collaborator

brianpos commented Mar 1, 2026

Yes there are several open issues for it.
This is the most direct exat issue as logged.
https://jira.hl7.org/browse/FHIR-53249
But also https://jira.hl7.org/browse/FHIR-49525 and https://jira.hl7.org/browse/FHIR-53250

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants