Skip to content

Implement calendar duration conversions for toQuantity(unit) and convertsToQuantity(unit) #2505

@piotrszul

Description

@piotrszul

Overview

The toQuantity(unit) and convertsToQuantity(unit) functions currently support calendar duration units (years, months, weeks, days, hours, minutes, seconds, milliseconds) but do not perform conversions between them. This issue tracks the implementation of calendar duration conversion capabilities.

Current Implementation

The current implementation:

  • Accepts calendar duration literals (e.g., '4 days', '1 year', '3 months')
  • Performs exact string matching on unit codes (e.g., '4 days'.toQuantity('days') works)
  • Returns empty when units don't match (e.g., '4 days'.toQuantity('weeks') returns empty)
  • Does not convert between calendar duration units

Requested Enhancement

Implement calendar duration conversions so that:

  • Definite duration units can be converted (e.g., days ↔ hours, minutes ↔ seconds)
  • Proper handling of indefinite durations (years, months) per FHIRPath specification
  • Conversion follows the calendar duration conversion factors specified in FHIRPath spec

Calendar Duration Conversion Factors (from FHIRPath spec)

From the FHIRPath specification (section on Quantity Conversion):

Duration Conversion Factor
1 year 365 days
1 month 30 days
1 week 7 days
1 day 24 hours
1 hour 60 minutes
1 minute 60 seconds
1 second 1000 milliseconds

Note: Years and months are indefinite durations and their conversions may need special handling.

Examples

'1 week'.toQuantity('days')       // Should return 7 days
'24 hours'.toQuantity('days')     // Should return 1 day
'60 minutes'.toQuantity('hours')  // Should return 1 hour

Implementation Notes

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    fhirpathRelated to fhirpath reference implementationnew featureNew feature or request

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions