Skip to content

Export audiograms with their sensitivity test details - #205

Draft
PSchmiedmayer wants to merge 6 commits into
native/sdk-27-2-collectionfrom
healthkit-audiograms
Draft

PSchmiedmayer wants to merge 6 commits into
native/sdk-27-2-collectionfrom
healthkit-audiograms

Conversation

@PSchmiedmayer

Copy link
Copy Markdown
Member

♻️ Current situation & Problem

This replaces #195, which closed when its branch was merged into the integration branch; the branch and commits are unchanged.
GroveHealthKitFHIR listed HKAudiogramSample as a type it did not convert yet, so an exporter refused every audiogram.
The HealthKit guide's audiogram panel had one threshold per ear at each LOINC-coded frequency and nothing else.
An HKAudiogramSensitivityTest also states its conduction method, whether it was masked and the clamping bounds of the source, and a test can use a frequency that has no LOINC code.
SchmiedmayerLab/grove-fhir#87 adds a sensitivity test extension on every panel component that holds these facts, and lets the panel state the sample's whole period.
This change implements that contract in Grove.

⚙️ Release Notes

  • An audiogram exports as one audiogram panel Observation with one component per sensitivity test and no value, through the existing .sample(_:) record.
  • A test at an ear and frequency the guide codes uses that component's LOINC code and the frequency the guide fixes for it.
  • Any other test keeps its exact frequency under a text-only code, such as "Air conduction threshold, right ear, 1250.5 Hz".
  • Frequencies are compared in whole millihertz, as the guide's panel invariant compares them.
  • Each component carries the healthkit-audiogram-sensitivity-test extension with the frequency, ear and conduction method, the masking state where HealthKit exposes it, and the clamping bounds where the source states any.
  • Components are ordered by frequency, then ear.
  • Before iOS 18.1, macOS 15.1, watchOS 11.1 and visionOS 2.1, HealthKit exposes only each ear's air-conduction sensitivity, so those components carry no masking state or clamping bounds.
  • An audiogram that lasts states its whole period, and one without duration states an instant.
  • An audiogram without points, a point without tests, a second test of one ear at one frequency, a frequency that is not positive, and a clamping range whose lower bound is not below its upper bound are refused as an invalid shape.
  • A conduction method other than air or an unknown side is refused as an unsupported value.
  • The contract generator emits the measurement's component extension and the members each component fixes, so the ear, frequency and extension URL come from the guide.
  • The projection back into HealthKit does not invert an audiogram and refuses it as measurementNotMappable.
  • The generated contract follows grove-fhir 078aa1c170cdf027e9f71bded85b8153229f31ad, the head of Preserve HealthKit audiogram sensitivity test details grove-fhir#87, which Scripts/validate-fhir-conformance.sh and the test workflow pin by commit.
try await exporter.export(records: [.sample(audiogram)]) { export in // audiogram: HKAudiogramSample
    if let record = export.record {
        try stage(record.json)
    }
}

A component at a frequency the guide does not code:

{
  "code": { "text": "Air conduction threshold, right ear, 1250.5 Hz" },
  "extension": [{
    "url": "https://grovealliance.org/fhir/healthkit/StructureDefinition/healthkit-audiogram-sensitivity-test",
    "extension": [
      { "url": "frequency", "valueQuantity": { "value": 1250.5, "unit": "Hz", "system": "http://unitsofmeasure.org", "code": "Hz" } },
      { "url": "ear", "valueCode": "right" },
      { "url": "conduction", "valueCode": "air" },
      { "url": "masked", "valueBoolean": false }
    ]
  }],
  "valueQuantity": { "value": 30, "unit": "dB", "system": "http://unitsofmeasure.org", "code": "dB" }
}

📚 Documentation

  • The GroveHealthKitFHIR DocC catalog describes how an audiogram exports and which details are missing on earlier systems.
  • The new audiogram content type documents its coding, ordering and refusal rules in comments.

✅ Testing

  • HealthKitAudiogramContentTests is new and covers coded components with masking and clamping bounds, exact uncoded frequencies, the millihertz comparison, per-ear masking and component order, the refused shapes, and the period or instant of a whole audiogram.
  • HealthKitContentCompilerTests adds a case that refuses an audiogram contract without its component extension or with a component that fixes no single ear and frequency.
  • The new goldens guide-example-audiogram and audiogram-test-details join the validated conformance fixtures.
  • guide-example-audiogram reproduces the guide's HealthkitAudiogramPanelExample, which Scripts/check-ig-example-containment.py now pairs with it.
  • audiogram-test-details covers a six-minute test with a masked, clamped coded frequency and two frequencies the guide does not code.
  • The content invariants no longer list the audiogram as not convertible, and the content corpus and guide examples are regenerated.
  • test_generate_grove_fhir_swift_contract.py covers the generated component extension and fixed members, and refuses extension values the generator cannot type.

Code of Conduct & Contributing Guidelines

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

An HKAudiogramSample converts to the audiogram panel: one component per
sensitivity test, coded where the catalog names its ear and frequency and
labeled with its exact frequency otherwise, each carrying the frequency,
ear, conduction method, masking state and clamping bounds in the
sensitivity-test extension. A test that lasts states its whole period.

The generator emits the catalog's component extension and the members
each component fixes, so the ear, frequency and extension URL come from
the guide instead of the component ids.
Pins grove-fhir to the audiogram guide branch at ce72a63, which contains
grove-fhir 0.9.0, and regenerates the 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