Skip to content

Export food correlations with their members - #164

Open
PSchmiedmayer wants to merge 7 commits into
healthkit-file-recordingsfrom
healthkit-food
Open

PSchmiedmayer wants to merge 7 commits into
healthkit-file-recordingsfrom
healthkit-food

Conversation

@PSchmiedmayer

@PSchmiedmayer PSchmiedmayer commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

♻️ Current situation & Problem

This PR builds on #160.

The Grove FHIR guide defines the healthkit-food-correlation profile, but the exporter refused every food correlation, saved or unsaved, with notYetConvertible(.food).

A food correlation groups nutrient samples that are HealthKit samples of their own. A study can collect the same nutrient from its own query and as a member of a correlation. Exporting a sample again at another conversion instant creates a new version of the same source record, so converting members at the correlation's instant would give one nutrient two versions whenever the two queries ran at different times. Trove keeps the conversion instant it first used for each HealthKit UUID, so a nutrient keeps its record version whichever query sees it first.

⚙️ Release Notes

  • A food correlation converts to one eating-occasion Observation with the healthkit-food-correlation profile, a Period effective time and no value. Its hasMember references each member's Observation by its source-output identifier.

  • Each member is exported as a record of its own, equal to the record its own query produces, under every disclosure option, source classification and device token policy. The ECG's symptoms and the food members now share one companion mechanism in the exporter. receive is called once for the correlation and once per member, members in UUID order.

  • A correlation converts as a whole. No members, a repeated member or a member that is no dietary quantity sample is refused with invalidValue(.food, .shapeInvalid), and any member failure yields one refusal for the correlation and no member record.

  • Both export methods take the retained conversion instant per HealthKit UUID. A sample without an entry uses at, also a member or symptom whose grouping has an entry. An instant FHIR cannot state throws ExchangeIdentityError.invalidInstant before anything is converted. The parameter defaults to [:].

    try await exporter.export(
        records: [.sample(foodCorrelation)],
        at: .now,
        conversionInstants: [foodCorrelation.uuid: firstSeen, protein.uuid: proteinFirstSeen]
    ) { export in
        // One export for the eating occasion, then one per member.
    }
  • A member also passed as its own record in the same call is exported twice.

  • An unsaved food correlation converts like a saved one. A member that names no source states the correlation's revision, as HealthKit attributes a saved correlation's members to the correlation's source.

  • The retraction of a food correlation targets its source record, and the food catalog entry states the food-correlation output.

📚 Documentation

GroveHealthKitFHIR.md and ConfiguringTheExporter.md describe food correlations, their members and conversionInstants. Both export methods gain parameter documentation, and DocC links follow the new signatures.

✅ Testing

  • HealthKitFoodContentTests (new): the eating occasion's profile, value and hasMember references, and members equal to their standalone records; per-UUID conversion instants keep a member's standalone version and a NaN instant throws first; a retry is identical and members keep their own metadata; members follow the non-identifying preset; empty, repeated and non-nutrient members are rejected.
  • HealthKitFHIRExporterUnsavedSampleTests.unsavedFoodStatesTheSavingRevision: an unsaved food correlation exports the same records as the saved one.
  • ContentInvariantTests, HealthKitAggregateConversionTests, HealthKitConverterTests and HealthKitFHIRExporterTests treat food as convertible. batchReportsEveryFailureWithoutDroppingRecords uses a vision prescription as its refused input.
  • The content corpus regenerates three food vectors: the correlation row, its retraction and its catalog entry.

Code of Conduct & Contributing Guidelines

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

@PSchmiedmayer
PSchmiedmayer added this pull request to stack #166 November 18, 2026 16:52
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3ea5d938-d68c-431c-a754-c00600d02099

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • 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

The guide admits HealthKit's food correlation, but the exporter refused it
as not yet convertible. A food correlation now converts to one
eating-occasion Observation that references its nutrient members, each
exported as a record of its own under the same disclosure options, with
its own writer and recording-device facts. An ECG's symptoms and a food
correlation's members share one companion mechanism.

export gains conversionInstants, the retained conversion instant per
HealthKit UUID, so a member keeps its record version whether it is
collected alone or through its correlation.

The content corpus changes two food vectors: the retraction now targets
the food record, and the catalog entry states its food-correlation
output.
State for `export(records:at:conversionInstants:receive:)` what each
parameter means, including that a member or symptom without its own
conversion instant uses `instant` rather than its grouping's entry.
An unsaved food correlation converts like a saved one: the eating
occasion and each nutrient member become records, and a member that
names no source states the revision HealthKit would stamp on saving the
correlation, as HealthKit attributes a saved correlation's members to
its source. Before, an unsaved food correlation reached the generic
conversion and was refused as an invalid shape.
@PSchmiedmayer
PSchmiedmayer removed this pull request from stack #166 November 28, 2026 00:16
@PSchmiedmayer
PSchmiedmayer changed the base branch from sensorkit-preparation to healthkit-file-recordings November 28, 2026 00:17
@PSchmiedmayer
PSchmiedmayer added this pull request to stack #178 November 28, 2026 00:17
@PSchmiedmayer
PSchmiedmayer marked this pull request as ready for review December 6, 2026 06:24
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