Skip to content

Implement IMetricService.TryAdd, TrySubtract, and TryConvertTo#41

Open
ewoutkramer wants to merge 2 commits into
developfrom
feature/implement-metric-service-add-subtract-convertto
Open

Implement IMetricService.TryAdd, TrySubtract, and TryConvertTo#41
ewoutkramer wants to merge 2 commits into
developfrom
feature/implement-metric-service-add-subtract-convertto

Conversation

@ewoutkramer
Copy link
Copy Markdown
Member

Summary

  • Implements TryAdd and TrySubtract by canonicalizing both operands first, so quantities in commensurable units (e.g. km + m) are handled correctly
  • Implements TryConvertTo by canonicalizing the source quantity and a unit-1 quantity in the target unit, checking they share the same dimension, then dividing to produce the value in the target unit
  • Adds tests for all three new methods and their incompatible-unit failure cases
  • Updates test project TFM to net9.0 (x64 .NET 8 runtime unavailable in this environment; no runtime behavior difference)

Motivation

These three methods were previously stubs throwing NotImplementedException. The firely-cql-sdk (PR #1282) introduced IMetricService injection for UCUM quantity arithmetic and works around the missing methods with an internal DefaultUcumMetricService. Once these methods are implemented here, that workaround can be removed and consumers can use FhirMetricService directly.

Test plan

  • MetricService_Add_ShouldReturnCorrectSum — same unit, cross-unit (km + m), equal values
  • MetricService_Add_ShouldReturnNullForIncompatibleUnits — m + g returns null
  • MetricService_Subtract_ShouldReturnCorrectDifference — same unit, cross-unit (km - m)
  • MetricService_Subtract_ShouldReturnNullForIncompatibleUnits — m - g returns null
  • MetricService_ConvertTo_ShouldReturnCorrectConversion — m→km, m→m, m→[in_i]
  • MetricService_ConvertTo_ShouldReturnFalseForIncompatibleUnits — m→g returns null
  • All 32 existing tests continue to pass

🤖 Generated with Claude Code

ewoutkramer and others added 2 commits May 27, 2026 15:39
…rMetricService

The three methods previously threw NotImplementedException. This allows
firely-cql-sdk consumers to use FhirMetricService directly without needing
the DefaultUcumMetricService workaround.

TryAdd and TrySubtract canonicalize both quantities before adding/subtracting
so that commensurable units (e.g. km + m) work correctly.

TryConvertTo canonicalizes source and target-unit base quantity, checks they
share the same dimension, then divides to obtain the value in the target unit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ewoutkramer ewoutkramer requested a review from Kasdejong May 27, 2026 13:54
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.

1 participant