Implement IMetricService.TryAdd, TrySubtract, and TryConvertTo#41
Open
ewoutkramer wants to merge 2 commits into
Open
Implement IMetricService.TryAdd, TrySubtract, and TryConvertTo#41ewoutkramer wants to merge 2 commits into
ewoutkramer wants to merge 2 commits into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TryAddandTrySubtractby canonicalizing both operands first, so quantities in commensurable units (e.g.km+m) are handled correctlyTryConvertToby 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 unitnet9.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) introducedIMetricServiceinjection for UCUM quantity arithmetic and works around the missing methods with an internalDefaultUcumMetricService. Once these methods are implemented here, that workaround can be removed and consumers can useFhirMetricServicedirectly.Test plan
MetricService_Add_ShouldReturnCorrectSum— same unit, cross-unit (km + m), equal valuesMetricService_Add_ShouldReturnNullForIncompatibleUnits— m + g returns nullMetricService_Subtract_ShouldReturnCorrectDifference— same unit, cross-unit (km - m)MetricService_Subtract_ShouldReturnNullForIncompatibleUnits— m - g returns nullMetricService_ConvertTo_ShouldReturnCorrectConversion— m→km, m→m, m→[in_i]MetricService_ConvertTo_ShouldReturnFalseForIncompatibleUnits— m→g returns null🤖 Generated with Claude Code