### Create and Start a Bulk Health Export Session Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKitBulkExport/SpeziHealthKitBulkExport.docc/BulkHealthExporter.md This code demonstrates how to create a Bulk Export Session with a custom Batch Processor and start the export. It defines a static identifier for the session and specifies the sample types to export. The session is created using the bulkExporter instance and then started. ```swift extension BulkExportSessionIdentifier { static let backgroundExport = Self("my-bulk-export-session") } // create the session (or obtain a previously-created session) let session = try await bulkExporter.session( withId: .backgroundExport, for: [SampleType.activeEnergy, SampleType.heartRate, SampleType.stepCount], using: FirebaseUploader() ) // start the session try session.start() ``` -------------------------------- ### SpeziAppDelegate Configuration Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/README.md Example configuration of the HealthKit module within a SpeziAppDelegate, including collecting various sample types and requesting read access. ```swift class ExampleAppDelegate: SpeziAppDelegate { override var configuration: Configuration { Configuration(standard: ExampleStandard()) { HealthKit { CollectSamples(.activeEnergyBurned) CollectSamples(.stepCount, start: .manual) CollectSamples(.pushCount, start: .manual) CollectSamples(.heartRate, continueInBackground: true) CollectSamples(.electrocardiogram, start: .manual) RequestReadAccess(quantity: [.bloodOxygen]) } } } } ``` -------------------------------- ### Health Data Collection Example Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/README.md Example implementation of a Standard conforming to HealthKitConstraint for handling new and deleted HealthKit samples. ```swift actor ExampleStandard: Standard, HealthKitConstraint { // Add the newly collected HealthKit samples to your application. func handleNewSamples( _ addedSamples: some Collection & Sendable, ofType sampleType: SampleType ) async { // ... } // Remove the deleted HealthKit objects from your application. func handleDeletedObjects( _ deletedObjects: some Collection & Sendable, ofType sampleType: SampleType ) async { // ... } } ``` -------------------------------- ### Exercise Activities Sample Types Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKit/SpeziHealthKit.docc/SampleType+QuantityTypes.md Sample types for various exercise activities. ```APIDOC ## Exercise Activities Sample Types ### Description Provides sample types for various exercise activities. ### Sample Types - `SampleType/underwaterDepth` - `SampleType/waterTemperature` - `SampleType/crossCountrySkiingSpeed` - `SampleType/distanceCrossCountrySkiing` - `SampleType/cyclingCadence` - `SampleType/cyclingFunctionalThresholdPower` - `SampleType/cyclingPower` - `SampleType/cyclingSpeed` - `SampleType/paddleSportsSpeed` - `SampleType/distancePaddleSports` - `SampleType/rowingSpeed` - `SampleType/distanceRowing` - `SampleType/distanceSkatingSports` - `SampleType/estimatedWorkoutEffortScore` - `SampleType/physicalEffort` - `SampleType/workoutEffortScore` ``` -------------------------------- ### Configure HealthKit Data Collection and Access Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKit/SpeziHealthKit.docc/ModuleConfiguration.md Use the HealthKit configuration block to define sample collection and read access requirements. ```swift HealthKit { CollectSamples(.stepCount) CollectSamples(.heartRate, continueInBackground: true) RequestReadAccess(quantity: [.heartRate, .bloodOxygen]) } ``` -------------------------------- ### Configure HealthKit Module Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKit/SpeziHealthKit.docc/SpeziHealthKit.md Register the HealthKit module in your SpeziAppDelegate configuration to define data collection types and access requests. ```swift class ExampleAppDelegate: SpeziAppDelegate { override var configuration: Configuration { Configuration(standard: ExampleStandard()) { HealthKit { CollectSamples(.activeEnergyBurned) CollectSamples(.stepCount, start: .manual) CollectSamples(.pushCount, start: .manual) CollectSamples(.heartRate, continueInBackground: true) CollectSamples(.electrocardiogram, start: .manual) RequestReadAccess(quantity: [.bloodOxygen]) } } } } ``` -------------------------------- ### Conform to HealthKitConstraint Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKit/SpeziHealthKit.docc/SpeziHealthKit.md Implement the HealthKitConstraint protocol in your Standard to handle new and deleted HealthKit samples. ```swift actor ExampleStandard: Standard, HealthKitConstraint { // Add the newly collected HealthKit samples to your application. func handleNewSamples( _ addedSamples: some Collection & Sendable, ofType sampleType: SampleType ) async { // ... } // Remove the deleted HealthKit objects from your application. func handleDeletedObjects( _ deletedObjects: some Collection & Sendable, ofType sampleType: SampleType ) async { // ... } } ``` -------------------------------- ### Visualize Blood Oxygen Samples with HealthChart Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKitUI/SpeziHealthKitUI.docc/HealthChart.md Use HealthKitQuery to fetch blood oxygen samples over the past week and display them as a line chart using HealthChart. Ensure HealthKitQuery is configured with the desired SampleType and time range. ```swift @HealthKitQuery(.bloodOxygen, timeRange: .week) var bloodOxygenSamples var body: some View { HealthChart { HealthChartEntry($bloodOxygenSamples, drawingConfig: .init(mode: .line, color: .blue)) } } ``` -------------------------------- ### Activity Sample Types Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKit/SpeziHealthKit.docc/SampleType+QuantityTypes.md Sample types related to physical activity tracking. ```APIDOC ## Activity Sample Types ### Description Provides a list of sample types for tracking various physical activities. ### Sample Types - `SampleType/stepCount` - `SampleType/distanceWalkingRunning` - `SampleType/runningGroundContactTime` - `SampleType/runningPower` - `SampleType/runningSpeed` - `SampleType/runningStrideLength` - `SampleType/runningVerticalOscillation` - `SampleType/distanceCycling` - `SampleType/pushCount` - `SampleType/distanceWheelchair` - `SampleType/swimmingStrokeCount` - `SampleType/distanceSwimming` - `SampleType/distanceDownhillSnowSports` - `SampleType/basalEnergyBurned` - `SampleType/activeEnergyBurned` - `SampleType/flightsClimbed` - `SampleType/appleExerciseTime` - `SampleType/appleMoveTime` - `SampleType/appleStandTime` - `SampleType/vo2Max` - `SampleType/timeInDaylight` ``` -------------------------------- ### UV Exposure Sample Types Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKit/SpeziHealthKit.docc/SampleType+QuantityTypes.md Sample types for tracking ultraviolet (UV) exposure. ```APIDOC ## UV Exposure Sample Types ### Description Provides a sample type for tracking UV exposure. ### Sample Types - `SampleType/uvExposure` ``` -------------------------------- ### Body Measurements Sample Types Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKit/SpeziHealthKit.docc/SampleType+QuantityTypes.md Sample types for recording body composition and measurements. ```APIDOC ## Body Measurements Sample Types ### Description Provides a list of sample types for recording various body measurements. ### Sample Types - `SampleType/height` - `SampleType/bodyMass` - `SampleType/bodyMassIndex` - `SampleType/leanBodyMass` - `SampleType/bodyFatPercentage` - `SampleType/waistCircumference` - `SampleType/appleSleepingWristTemperature` - `SampleType/appleSleepingBreathingDisturbances` ``` -------------------------------- ### Querying Health Data in SwiftUI Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/README.md Demonstrates how to use HealthKitQuery property wrappers to access HealthKit data within a SwiftUI View. ```swift struct ExampleView: View { @HealthKitQuery(.heartRate, timeRange: .today) private var heartRateSamples var body: some View { ForEach(heartRateSamples) { sample in // ... } } } ``` -------------------------------- ### Alcohol Consumption Sample Types Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKit/SpeziHealthKit.docc/SampleType+QuantityTypes.md Sample types for tracking alcohol consumption. ```APIDOC ## Alcohol Consumption Sample Types ### Description Provides sample types for tracking alcohol consumption. ### Sample Types - `SampleType/bloodAlcoholContent` - `SampleType/numberOfAlcoholicBeverages` ``` -------------------------------- ### Hearing Sample Types Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKit/SpeziHealthKit.docc/SampleType+QuantityTypes.md Sample types for monitoring audio exposure and hearing health. ```APIDOC ## Hearing Sample Types ### Description Provides sample types for monitoring audio exposure. ### Sample Types - `SampleType/environmentalAudioExposure` - `SampleType/headphoneAudioExposure` - `SampleType/environmentalSoundReduction` ``` -------------------------------- ### Implement Custom Batch Processor for Firebase Upload Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKitBulkExport/SpeziHealthKitBulkExport.docc/BulkHealthExporter.md This struct implements the BulkHealthExporter.BatchProcessor protocol to upload HealthKit samples to Firebase. It defines the process function to iterate over samples, create Firestore documents, and commit them in batches. The Output type is Void as no further on-device processing is needed. ```swift struct FirebaseUploader: BulkHealthExporter.BatchProcessor { func process(_ samples: consuming [Sample], of sampleType: SampleType) async throws { let batch = Firestore.firestore().batch() for sample in samples { let document = db.collection("healthData").document(sample.uuid.uuidString) try batch.setData(from: sample.resource(), for: document) } try await batch.commit() } } ``` -------------------------------- ### Mobility Sample Types Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKit/SpeziHealthKit.docc/SampleType+QuantityTypes.md Sample types for assessing mobility and gait. ```APIDOC ## Mobility Sample Types ### Description Provides sample types for assessing mobility and gait. ### Sample Types - `SampleType/appleWalkingSteadiness` - `SampleType/sixMinuteWalkTestDistance` - `SampleType/walkingSpeed` - `SampleType/walkingStepLength` - `SampleType/walkingAsymmetryPercentage` - `SampleType/walkingDoubleSupportPercentage` - `SampleType/stairAscentSpeed` - `SampleType/stairDescentSpeed` ``` -------------------------------- ### Nutrition Sample Types Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKit/SpeziHealthKit.docc/SampleType+QuantityTypes.md Sample types for tracking dietary intake. ```APIDOC ## Nutrition Sample Types ### Description Provides a list of sample types for tracking dietary intake. ### Sample Types - `SampleType/dietaryBiotin` - `SampleType/dietaryCaffeine` - `SampleType/dietaryCalcium` - `SampleType/dietaryCarbohydrates` - `SampleType/dietaryChloride` - `SampleType/dietaryCholesterol` - `SampleType/dietaryChromium` - `SampleType/dietaryCopper` - `SampleType/dietaryEnergyConsumed` - `SampleType/dietaryFatMonounsaturated` - `SampleType/dietaryFatPolyunsaturated` - `SampleType/dietaryFatSaturated` - `SampleType/dietaryFatTotal` - `SampleType/dietaryFiber` - `SampleType/dietaryFolate` - `SampleType/dietaryIodine` - `SampleType/dietaryIron` - `SampleType/dietaryMagnesium` - `SampleType/dietaryManganese` - `SampleType/dietaryMolybdenum` - `SampleType/dietaryNiacin` - `SampleType/dietaryPantothenicAcid` - `SampleType/dietaryPhosphorus` - `SampleType/dietaryPotassium` - `SampleType/dietaryProtein` - `SampleType/dietaryRiboflavin` - `SampleType/dietarySelenium` - `SampleType/dietarySodium` - `SampleType/dietarySugar` - `SampleType/dietaryThiamin` - `SampleType/dietaryVitaminA` - `SampleType/dietaryVitaminB12` - `SampleType/dietaryVitaminB6` - `SampleType/dietaryVitaminC` - `SampleType/dietaryVitaminD` - `SampleType/dietaryVitaminE` - `SampleType/dietaryVitaminK` - `SampleType/dietaryWater` - `SampleType/dietaryZinc` ``` -------------------------------- ### Bulk-Exporting FHIR-Encoded Data to Disk Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKitBulkExport/SpeziHealthKitBulkExport.docc/BulkHealthExporter.md Implements a BatchProcessor to map HealthKit samples into FHIR resources and write them to temporary JSON files. The session returns an AsyncStream of URLs pointing to the exported files. ```swift extension BulkExportSessionIdentifier { static let backgroundFHIRExport = Self("my-fhir-bulk-export-session") } struct FHIREncodedJSONExporter: BatchProcessor { func process(_ samples: consuming [Sample], of sampleType: SampleType) throws -> URL { let resources = try samples.mapIntoResourceProxies() // using HealthKitOnFHIR let encoded = try JSONEncoder().encode(resources) let url = URL.temporaryDirectory.appendingPathComponent(UUID().uuidString, conformingTo: .json) try encoded.write(to: url) return url } } // create the session let session = try await bulkExporter.session( withId: .backgroundFHIRExport, for: [SampleType.activeEnergy, SampleType.heartRate, SampleType.stepCount], using: FHIREncodedJSONExporter() ) // start the session let results = try session.start() // await the results Task { for await url in results { // process the JSON file at `url` in some way } } ``` -------------------------------- ### Visualizing Health Data with HealthChart Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/README.md Shows how to use the HealthChart view to visualize query results from HealthKit. ```swift struct ExampleView: View { @HealthKitQuery(.heartRate, timeRange: .today) private var heartRateSamples var body: some View { HealthChart { HealthChartEntry($heartRateSamples, drawingConfig: .init(mode: .line, color: .red)) } } } ``` -------------------------------- ### Vital Signs Sample Types Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKit/SpeziHealthKit.docc/SampleType+QuantityTypes.md Sample types for recording key physiological vital signs. ```APIDOC ## Vital Signs Sample Types ### Description Provides a list of sample types for recording vital signs. ### Sample Types - `SampleType/heartRate` - `SampleType/restingHeartRate` - `SampleType/walkingHeartRateAverage` - `SampleType/heartRateVariabilitySDNN` - `SampleType/heartRateRecoveryOneMinute` - `SampleType/atrialFibrillationBurden` - `SampleType/bloodOxygen` - `SampleType/bodyTemperature` - `SampleType/bloodPressureDiastolic` - `SampleType/bloodPressureSystolic` - `SampleType/respiratoryRate` ``` -------------------------------- ### Reproductive Health Sample Types Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKit/SpeziHealthKit.docc/SampleType+QuantityTypes.md Sample types related to reproductive health tracking. ```APIDOC ## Reproductive Health Sample Types ### Description Provides a sample type for tracking basal body temperature. ### Sample Types - `SampleType/basalBodyTemperature` ``` -------------------------------- ### Lab Results Sample Types Source: https://github.com/stanfordspezi/spezihealthkit/blob/main/Sources/SpeziHealthKit/SpeziHealthKit.docc/SampleType+QuantityTypes.md Sample types for recording laboratory test results. ```APIDOC ## Lab Results Sample Types ### Description Provides a list of sample types for recording lab results. ### Sample Types - `SampleType/bloodGlucose` - `SampleType/electrodermalActivity` - `SampleType/forcedExpiratoryVolume1` - `SampleType/forcedVitalCapacity` - `SampleType/inhalerUsage` - `SampleType/insulinDelivery` - `SampleType/numberOfTimesFallen` - `SampleType/peakExpiratoryFlowRate` - `SampleType/peripheralPerfusionIndex` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.