Repository navigation
Convert Withings, Oura and Google Health records - #165
Open
PSchmiedmayer wants to merge 11 commits into
Open
PSchmiedmayer wants to merge 11 commits into
PSchmiedmayer wants to merge 11 commits into
Conversation
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
GroveProviderFHIR converts typed connected-provider records into exchange records with the shared identity, Device and conversion Provenance infrastructure. ProviderFHIRConverter converts Withings measure groups and summaries, Oura documents, Google Health data points and native provider recordings, each into one complete record or explicit omissions. ProviderCapabilities states the conversion support of every source token of the pinned provider catalog, with its generated ProviderImplementationStatus. Oura and Google Health times are ProviderTimestamp and ProviderInterval values, so outputs state the source's exact spelling, UTC offset and fractional digits; Withings epoch-second times use Date. The module builds on Linux, and the generated contract adds the provider catalog.
Withings, Oura and Google Health sleep-stage durations were converted to hours but stated under the stage contracts' `min` unit. One helper now converts a duration into the time unit its contract names, so total sleep is stated in hours and each stage in minutes. Tests assert the value, code and unit of every unit conversion of the three providers.
`ProviderNativeRecording.interval` states an Oura or Google Health period as a `ProviderInterval`, so the document keeps the source's UTC offset and digits, while a Withings period stays a `DateInterval`. The initializer throws only `ValidationError` besides cancellation, and `ProviderCivilDay` throws only `ProviderConversionError`. The product and documentation entries now sit next to GroveFHIR, and a test checks that every native recording stream is advertised as its provider's native recording token.
A duration that doesn't divide evenly into its contract's unit, such as 25,230 seconds in hours, is rounded half to even at four decimal places instead of stating a 38-digit repeating decimal. The unit tests cover a non-divisible duration and the identity mappings (oxygen saturation, temperature, heart rate variability and respiratory rate), the Google Health tests use a connection of their own, the native recording token test moves to the recording tests, and the recording interval check reads plainly.
A `switch` expression takes `try` on each case, not in front of the switch.
`ProviderConversionError.invalidQuantity` always carries the identifier of the measurement or measurement component, where a value outside a quantity's domain carried its unit code before. The documentation calls identifiers stable and custody persistent.
ValidationError.invalidPath names every case the shared relative attachment path check refuses.
PSchmiedmayer
force-pushed
the
healthkit-food
branch
from
November 28, 2026 00:17
d8b8500 to
5fcd325
Compare
PSchmiedmayer
force-pushed
the
provider-fhir-conversion
branch
from
November 28, 2026 00:17
b59b3dc to
3b160e7
Compare
PSchmiedmayer
changed the base branch from
healthkit-food
to
fhir-measurement-catalog
November 28, 2026 00:17
This was referenced Nov 28, 2026
PSchmiedmayer
marked this pull request as ready for review
December 6, 2026 06:24
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.
♻️ Current situation & Problem
This PR builds on #161.
The grove-fhir guide defines profiles, a source catalog and identity rules for connected providers (Withings, Oura and the Google Health API), and GroveFHIRContract implements the shared identity, Device and Provenance infrastructure they build on. Grove had no provider converter, so a study server had to write its own conversion against the guide. Trove's server connects participants' provider accounts and needs that conversion on Linux, with stable identities so a retried conversion produces the same record version, and with an explicit statement of every source element it does not convert.
GroveProviderFHIRconverts typed provider records the caller has already acquired. It does not fetch or resample data, and it never substitutes the retrieval time for a missing source time.⚙️ Release Notes
New product
GroveProviderFHIRfor Apple platforms and Linux, depending only on GroveFHIRContract, FHIRModelsExtensions and ModelsR4.ProviderFHIRConverter.convert(_:context:)takes aWithingsMeasureGroup,WithingsSummary,OuraRecord,GoogleHealthDataPointorProviderNativeRecording. EachProviderConversionResultholds at most one completeExchangeRecordand theomissionsthat name each element left out and why (notYetImplemented,notAdmitted,missingRequiredEvidence). Withings inputs return one result per source token.ProviderConversionContextholds the facts a retry reuses: producer, key space, persisted instant, source time zone and optional recording device. The key space is checked:.account(_:)for Withings and Google Health,.global(_:)for Oura, otherwiseinvalidScope.sourceIdentity(provider:sourceType:nativeRecordID:)exposes the identity for the caller's bookkeeping.Withings: a diastolic and systolic pair in one group forms one blood pressure panel, and a lone half is omitted. Values are scaled by their base-ten exponent as
Decimalwithout a binary floating-point step. A type stated twice throwsconflictingMeasurement(_:). Each populated summary field converts under its own token, and an absent field is never zero.Oura: an activity day runs from 04:00 to 04:00 in the day's time zone, so a day across a clock change keeps its real length. A sleep document without bedtime bounds produces no record.
Google Health: all admitted fields of one data point share one record, and SI inputs convert to the contract's units as exact decimals.
A workout without an evidenced activity code from the pinned contract produces no Observation, so no workout is reported as
other.Exact source times: Oura and Google Health times are
ProviderTimestampandProviderInterval, which keep the RFC 3339 spelling, offset and up to nine fractional digits, and compare instants to the nanosecond. Withings times stayDateand are written in the source time zone.Durations are stated in their contract's UCUM time unit and rounded half to even at four decimal places. A value outside its domain throws
invalidQuantity(_:)naming the measurement, and a source that does not match its contract throwsinvalidContract(_:).ProviderNativeRecordingholds exact provider JSON in aRecordingFilefor the four streams the guide admits as recordings. It validates the JSON within a byte limit (at most 64 MiB), requires a relative attachment path and aRecordingPayloadAdmission, and keeps each provider's period representation. The DocumentReference states the file's SHA-1 and byte count.ProviderCapabilities.sources(for:)lists every catalog row of a provider with its guide status, output profiles,conversionSupportand effective form, so a client can build its collection options from it.generate-grove-fhir-swift-contract.pygeneratesProviderImplementationStatusand the internalProviderContractfrom the guide's provider catalog, andCanonicalsexposes the provider extension URLs.📚 Documentation
A new GroveProviderFHIR DocC catalog covers identity and retries, structured values and native recording files. Every public type has symbol documentation, and
.spi.ymllists the new module.✅ Testing
New test target
GroveProviderFHIRTests, added to the GroveFHIR test plan:WithingsFHIRTests,OuraFHIRTestsandGoogleHealthAPIFHIRTests: every advertised structured source has a positive fixture. They also cover decimal scaling and overflow, blood pressure pairing, omissions, civil days and 04:00 activity days across clock changes, missing sleep bounds, a wrong key space, and exact unit conversion.OuraExactTimeTestsandProviderTimestampTests: source offsets and spellings survive daylight-saving transitions, ordering is exact across offsets and nanoseconds, and malformed or over-precise times are refused.ProviderUnitConversionTests: every unit conversion, domain errors, duration units and rounding.ProviderWorkoutTests: workouts without an evidenced activity emit nothing.ProviderRecordingFHIRTests: native streams keep their exact payload and identity; malformed JSON, duplicate members, path traversal and an exceeded limit are refused; recording periods keep their source representation.Code of Conduct & Contributing Guidelines
By creating and submitting this pull request, you agree to follow our Code of Conduct and Contributing Guidelines: