Skip to content

Export electrocardiograms whose symptoms cannot be read - #207

Draft
PSchmiedmayer wants to merge 10 commits into
healthkit-clinical-documentsfrom
healthkit-ecg-symptoms
Draft

PSchmiedmayer wants to merge 10 commits into
healthkit-clinical-documentsfrom
healthkit-ecg-symptoms

Conversation

@PSchmiedmayer

Copy link
Copy Markdown
Member

♻️ Current situation & Problem

This replaces #197, which closed when its branch was merged into the integration branch; the branch and commits are unchanged.
An HKElectrocardiogram can report its symptoms status as present while its symptom samples need their own read authorization.
HealthKit does not reveal a denied read: the symptom query returns no samples.
HKElectrocardiogram.correlatedSymptomSamples(from:) then returned an empty array, and the exporter refused the ECG as symptomsRequired, so the waveform and its average heart rate were lost.
The exporter also could not tell that case apart from a caller that never fetched the symptoms.
SchmiedmayerLab/grove-fhir#89 lets such an ECG keep its present status and carry one member with only the data-absent reason unknown.

⚙️ Release Notes

  • Breaking: HKElectrocardiogram.correlatedSymptomSamples(from:) returns the new HKElectrocardiogram.CorrelatedSymptoms instead of an array: .samples(_:), or .unreadable when the status is present and HealthKit returns no sample.
  • CorrelatedSymptoms.samples gives the array, empty when the symptoms are unreadable.
  • When the app may read only some symptom types, .samples(_:) holds the samples of those types.
  • Breaking: HealthKitFHIRExporter.Record.electrocardiogram(_:voltages:symptoms:) takes the new HealthKitFHIRExporter.Record.ElectrocardiogramSymptoms with the same two cases.
  • ElectrocardiogramSymptoms is expressible by an array literal, so existing call sites with a literal list of samples keep compiling.
  • An unreadable ECG keeps its present status and its waveform carries exactly one hasMember entry with only the data-absent-reason extension and code unknown.
  • A present status passed with no samples is still refused as symptomsRequired, and .unreadable with any other status is refused as unexpectedSymptoms.
  • HKElectrocardiogram.symptoms(from:) returns no symptoms when they are unreadable.
  • The exchange graph validator admits a data-absent member only where the guide's reference policy names the path and profile: the single hasMember entry of an Observation claiming the HealthKit ECG profile.
  • The generator emits these data-absent reference policies from the pinned guide.
  • The generated contract follows grove-fhir 88ba968c3f1f0a4c4ab65daaad297d686c3fc3ac, the head of State unreadable HealthKit ECG symptoms as unknown grove-fhir#89, which Scripts/validate-fhir-conformance.sh and the test workflow pin by commit.

Code that passed a variable of [HKCategorySample] maps the fetched state:

let symptoms: HealthKitFHIRExporter.Record.ElectrocardiogramSymptoms =
    switch try await ecg.correlatedSymptomSamples(from: healthKit) {
    case .samples(let samples): .samples(samples)
    case .unreadable: .unreadable
    }
try await exporter.export(records: [.electrocardiogram(ecg, voltages: voltages, symptoms: symptoms)]) { export in
    if let record = export.record {
        try stage(record.json)
    }
}

📚 Documentation

  • The GroveHealthKit DocC catalog lists HKElectrocardiogram.CorrelatedSymptoms.
  • The GroveHealthKitFHIR DocC catalog describes the unreadable state, the unknown member and the symptomsRequired refusal.
  • Both new enumerations document when HealthKit hides unreadable symptoms.

✅ Testing

  • HealthKitECGContentTests adds cases for a present ECG with unreadable symptoms, for refusing a data-absent member on another Observation, with another reason or beside other members, and for the exchange graph admitting it only at the policy's path and profile.
  • The new golden electrocardiogram-unreadable-symptoms joins the validated conformance fixtures and contains one member with the reason unknown.
  • The content corpus adds the vectors symptoms/unreadable and symptoms/unreadable-without-present-status.
  • The ECG fixtures and goldens pass symptoms through ElectrocardiogramSymptoms.
  • test_generate_grove_fhir_swift_contract.py covers the generated data-absent references and unreadable symptoms reason, and refuses policies the validator does not check and unreadable symptoms the generator does not emit.

Code of Conduct & Contributing Guidelines

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

HealthKit returns no symptom samples for a type the app may not read,
without saying so. An ECG whose symptoms status is present but whose
symptoms could not be read now states one data-absent member with the
reason unknown, and the contract admits such a Reference only at the
governed path the guide names. The generator emits these data-absent
reference policies.
HealthKit hides denied read access, so a present symptoms status with no readable sample is the only sign that the symptoms are unreadable. HKElectrocardiogram.correlatedSymptomSamples(from:) now returns that state as CorrelatedSymptoms.unreadable, and the exporter's electrocardiogram record takes ElectrocardiogramSymptoms, either the samples or unreadable. A present status passed without samples, as by a caller that skipped the fetch, is refused as symptomsRequired.
Pins grove-fhir to the ECG symptoms guide branch at aa185b7, which contains
grove-fhir 0.9.0, and regenerates the contracts from it. The generator
test's exchange protocol fixture keeps both the reference policy and the
governed source identifier, and the documentation keeps the unreadable
symptoms paragraph beside the clinical record text.
@PSchmiedmayer
PSchmiedmayer added this pull request to stack #208 December 4, 2026 22:46
@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

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