Skip to content

toQuantity() ignores its optional unit parameter #310

@luisfabib

Description

@luisfabib

The FHIRPath spec defines toQuantity() with an optional unit argument:
toQuantity([unit : String]). The parser correctly accepts 0 or 1 arguments, but
ToQuantity.evaluate() never reads or applies the argument — it is silently dropped.

Additionally, the parser does not star-unpack the argument list when constructing the
ToQuantity node, so the argument is lost before it even reaches evaluate().

Expected behaviour

'1.5'.toQuantity('mg') → 1.5 'mg'
'1.5'.toQuantity() → 1.5 '1' (dimensionless)

Actual behaviour

'1.5'.toQuantity('mg') → 1.5 '1' (unit argument ignored)

Suggested fix

  1. In parser.py: pass the optional unit string argument when constructing ToQuantity.
  2. In conversion.py: apply the unit argument in evaluate(), overriding the parsed unit
    if one is provided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfhir.pathRelated to the FHIRPath module

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions