Overview
The toQuantity(unit) and convertsToQuantity(unit) functions currently support the optional unit parameter using exact string matching only. This issue tracks the implementation of full UCUM unit conversion capabilities.
Current Implementation
The current implementation:
- Accepts an optional
unit parameter for both functions
- Performs exact string matching on unit codes (e.g.,
'10 'mg''.toQuantity('mg') works)
- Returns empty when units don't match (e.g.,
'10 'mg''.toQuantity('g') returns empty)
- This is compliant with FHIRPath spec which states: "Implementations are not required to support a complete UCUM implementation, and may return empty when the unit argument is used and it is different than the input quantity unit."
Requested Enhancement
Implement full UCUM unit conversion so that:
toQuantity(unit) converts the quantity value to the target unit (e.g., '1 'wk''.toQuantity('d') returns 7 'd')
convertsToQuantity(unit) returns true if conversion is possible between compatible units
- Support common UCUM conversions (length, mass, volume, time, etc.)
Examples
These test cases are currently excluded in config.yaml:
'1 'wk''.toQuantity('d').toString() = '7 'd'' // Should convert weeks to days
'1 'cm''.toQuantity('mm').value = 10 // Should convert cm to mm
Implementation Notes
- Implement test cases in
au.csiro.pathling.fhirpath.dsl.ConversionFunctionsDslTest - extract toQuantity(unit) tests for UCUM units to a separate method.
- Implement in
au.csiro.pathling.fhirpath.column.QuantityValue
- Leveraging existing UCUM integration (
au.csiro.pathling.encoders.terminology.ucum.Ucum)
- Ensure conversion accuracy and precision handling
- Document which UCUM conversions are supported
- Update test exclusions in
config.yaml once implemented
Related
Overview
The
toQuantity(unit)andconvertsToQuantity(unit)functions currently support the optional unit parameter using exact string matching only. This issue tracks the implementation of full UCUM unit conversion capabilities.Current Implementation
The current implementation:
unitparameter for both functions'10 'mg''.toQuantity('mg')works)'10 'mg''.toQuantity('g')returns empty)Requested Enhancement
Implement full UCUM unit conversion so that:
toQuantity(unit)converts the quantity value to the target unit (e.g.,'1 'wk''.toQuantity('d')returns7 'd')convertsToQuantity(unit)returns true if conversion is possible between compatible unitsExamples
These test cases are currently excluded in
config.yaml:Implementation Notes
au.csiro.pathling.fhirpath.dsl.ConversionFunctionsDslTest- extracttoQuantity(unit)tests for UCUM units to a separate method.au.csiro.pathling.fhirpath.column.QuantityValueau.csiro.pathling.encoders.terminology.ucum.Ucum)config.yamlonce implementedRelated
ConversionLogic.java:152-193ValidationLogic.java:123-183config.yaml:249-262