Skip to content

Collect the SDK 27.2 HealthKit types, headphone sensors and sleep sessions - #204

Draft
PSchmiedmayer wants to merge 17 commits into
m3-collection-basefrom
native/sdk-27-2-collection
Draft

PSchmiedmayer wants to merge 17 commits into
m3-collection-basefrom
native/sdk-27-2-collection

Conversation

@PSchmiedmayer

Copy link
Copy Markdown
Member

♻️ Current situation & Problem

This replaces #194, which closed when its branch was merged into the integration branch; the branch and commits are unchanged.
Compared with the 26.5 baseline, the iPhoneOS 27.2 SDK has three more HealthKit types, heart rate variability RMSSD, bleeding after menopause and menopausal state, and two SensorKit sensors, headphone motion and headphone settings.
SchmiedmayerLab/grove-fhir#86 moves the HealthKit and SensorKit catalogs to that SDK and registers the device-motion-samples and headphone-settings-samples recording formats.
Grove had no sample types or sensors for these sources, so an app could neither collect nor export them.
The headphone settings format marks its optional hearing-assistance columns as one nullable group: in each row they are all present or all absent.
Grove's CSV writer and reader had no notion of such a group.
SensorKit states an identifier for each sleep session, and Grove's sleep-session record kept only the session bounds.
GroveHealthKit also had no typed sample type for hypertension notifications, which HealthKit added in platform 26.2 and the HealthKit guide already covers.

⚙️ Release Notes

  • GroveHealthKit adds SampleType.heartRateVariabilityRMSSD, .bleedingAfterMenopause, .menopausalState and .hypertensionEvent, with their Linux identifiers and localized titles.
  • The platform 27 symbols exist only in the platform 27 SDKs, which ship with Swift 6.4, so their declarations sit behind #if compiler(>=6.4) and the package still builds with Xcode 26.
  • GroveHealthKitFHIR converts the three platform 27 types.
  • The menopausal state rule names a platform 27 symbol, so that type is not convertible on earlier systems or in a build with an earlier SDK.
  • The projection of an Observation back into a HealthKit sample refuses a type the running system lacks, such as RMSSD before platform 27, as measurementNotMappable.
  • GroveSensorKit adds Sensor.headphoneMotion and Sensor.headphoneSettings on iOS 27 and Sensor.sleepSessions on iOS 26.
  • A headphone motion sample keeps its own startDate and the timestamp at which SensorKit stored it, and headphone settings keep hearingAssistance as an optional group.
  • GroveSensorKitFHIR writes headphone motion batches as device-motion-samples and headphone settings batches as headphone-settings-samples tabular recordings.
  • RecordingCSVWriter.Field.unsignedInteger(UInt64) writes batch identifiers that can exceed Int.max, and the accelerometer and pressure recordings use it for their identifiers too.
  • A row whose nullable group is only partly filled is refused by the writer as incompleteNullableGroup(_:) and by the reader as incompleteNullableGroup(row:group:).
  • SensorKitSleepSessionRecord carries nativeSessionIdentifier, and SensorKitPreparedStructuredRecord(sleepSession:) prepares a session with that identifier in its retry evidence.
  • SensorKitFHIRExporter.Options.sleepSessionIdentifier discloses the identifier on the sleep-session Observation under a system the deployment owns.
  • The identifier is omitted by default and never enters a Grove identity.
  • The Observation carries one governed source identifier, so a disclosed session identifier takes the place of the record id that nativeIdentifier discloses.
  • The exporter refuses a reserved sleep-session system as reservedIdentifierSystem(_:), and one shared with the visit-location or native-identifier system as the new sharedIdentifierSystem(_:).
  • The generated contracts follow grove-fhir 6ea4528076c2e2457ba0d07376f1ee030bea0d78, the head of Move the HealthKit and SensorKit baselines to SDK 27.2 grove-fhir#86.
  • Scripts/validate-fhir-conformance.sh and the test workflow pin that commit with an empty version until a grove-fhir release contains it.
let rmssd = SampleType.heartRateVariabilityRMSSD // iOS 27
let motion = Sensor.headphoneMotion              // iOS 27
let sleep = Sensor.sleepSessions                 // iOS 26
let session = try SensorKitPreparedStructuredRecord(sleepSession: sample) // SRSleepSession.SafeRepresentation

var options = SensorKitFHIRExporter.Options()
options.sleepSessionIdentifier = .authorized(
    system: IdentifierSystem("https://study.example.org/fhir/NamingSystem/sensorkit-sleep-session")
)
let exporter = try SensorKitFHIRExporter(
    producer: producer,
    repositoryScope: repositoryScope,
    visitLocationIdentifierSystem: visitLocationSystem,
    options: options
)

📚 Documentation

  • The GroveHealthKit DocC catalog lists the four new sample types.
  • The GroveSensorKit entitlement table lists motion-headphone, headphone-settings and sleep-sessions.
  • The GroveSensorKitFHIR DocC catalog describes the headphone recordings, the sleep-session preparation and its retry evidence, and the sleepSessionIdentifier disclosure.
  • The new sensors, the sleep-session record and option, and the new error cases carry DocC comments.

✅ Testing

  • HealthKitPlatform27Tests is new and covers the RMSSD statistic, unit and interval, the intensity of bleeding after menopause, and each menopausal state as a point in time.
  • Platform27HealthKitTypeTests is new and checks the typed lookups, the canonical RMSSD unit and the localized titles of the new sample types.
  • Their cases check a type only where the system and SDK have it, on visionOS as well.
  • GroveHealthKitTests counts the known object types per platform.
  • The content corpus, its invariant tests and the category round trip skip the platform 27 vectors on systems or builds that lack the types.
  • The content corpus and the HealthKit guide examples are regenerated for the 27.2 baseline, with the new bleeding after menopause and menopausal state examples.
  • RecordingCSVWriterTests adds cases for nullable groups on write and read, for a column violation reported before its incomplete group, and for an identifier above Int.max.
  • SensorKitSleepIdentityTests is new and covers the exact disclosed identifier, its precedence over a disclosed record id, sessions without an identifier, and the refused identifier systems.
  • SensorKitSleepPreparationTests is new and covers the prepared bounds, the identifier in the retry evidence, an empty identifier and a negative duration.
  • SensorConformanceFixtureTests adds fixtures for a headphone motion recording with a batch identifier above Int64.max, headphone settings rows with and without hearing assistance, and a sleep session with a disclosed identifier.
  • The sleep-session fixtures use a testing identifier system that the FHIR validator accepts.
  • SensorKitFHIRCatalogTests, SensorKitOutputDefinitionTests and GroveSensorKitBridgeTests follow the catalog's 24 sensors.
  • The converter's source admission test uses a token that no catalog entry names, since headphone motion is now a catalog sensor.
  • test_generate_grove_sensor_swift_contract.py covers the generated nullable groups, and test_grove_fhir_pin.py admits a pin by commit alone.

Code of Conduct & Contributing Guidelines

By creating and submitting this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

Adds heart rate variability RMSSD, bleeding after menopause, menopausal
state and hypertension notifications to GroveHealthKit, with their Linux
identifiers and localizations. Symbols of the platform 27 SDK compile
only with Swift 6.4. GroveHealthKitFHIR converts the three platform 27
types; the menopausal state rule names a platform 27 symbol, so the type
is not yet convertible on earlier systems and in builds with an earlier
SDK.

GroveSensorKit adds the headphone motion, headphone settings and sleep
session sensors. The headphone samples write the device motion and
headphone settings recording formats; a motion sample states its start
date apart from the time SensorKit stored it, and batch identifiers are
written as unsigned integers. CSV columns of one nullable group are
absent or present together, and a row that breaks that rule is refused
as an incomplete nullable group when written and when read.

The generated contracts follow grove-fhir 6ea4528, which the conformance
check pins by commit until a release contains it.
SensorKitSleepSessionRecord carries the exact SRSleepSession identifier,
and SensorKitPreparedStructuredRecord(sleepSession:) prepares a session
with it in its retry evidence. Under the new sleepSessionIdentifier
option the sleep-session Observation states it as one more governed
source identifier, under a system of its own; it never enters a Grove
identity. A reserved system, or the system of the disclosed native
identifier, is refused when the exporter is created.
A sleep session's Observation carries one governed source identifier:
the session's own identifier, where the session states one and the
sleepSessionIdentifier option discloses it, else the record id. An
empty session identifier is a session without one, and the option's
system must differ from the visit-location system too.

The Codegen identifier definitions of the platform 27 types compile
only with Swift 6.4, and the headphone motion sensor imports SensorKit
publicly for its inlinable definition. The SensorKit catalog tests
follow the 0.8.3 catalog, and conformance fixtures cover the headphone
recordings and a disclosed sleep-session identifier. HealthKit tests
skip the platform 27 types on earlier systems and in builds with an
earlier SDK, where menopausal state is not yet convertible.
The reverse projection looks up its quantity or category type and
refuses an Observation whose type this system's HealthKit does not
have, such as RMSSD before platform 27, as not mappable. The corpus
grid comparison, the category round trip and the catalog matrix skip
the platform 27 types where the system lacks them.
The corpus reproduction and the per-row coverage check skip the vectors
of a platform 27 type, including its reverse projection, on a system or
build that lacks the type.
Headphone motion is now a catalog sensor, so the test uses a token that no catalog entry names.
The values are the public entitlement values of SensorKit's sensor descriptions in iOS 27.2.
The healthkit guide at 6ea4528 adds the bleeding after menopause and menopausal state examples, which the content corpus now converts.
The FHIR validator refuses an example.org system in the conformance fixtures.
The corpus reproduction skips a guide example whose HealthKit source type is a platform 27 type this system or build lacks, as it does for the other vectors of such a type. The guide examples of bleeding after menopause and menopausal state otherwise drift on iOS and watchOS 26 and on macOS 26.
Pins grove-fhir to the SDK 27.2 guide branch at 9740cbb, which contains
grove-fhir 0.9.0, and regenerates the format registry and SensorKit
contracts from it.
@coderabbitai

coderabbitai Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@PSchmiedmayer
PSchmiedmayer added this pull request to stack #208 December 4, 2026 22:46
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