Skip to content

Commit

Permalink
extend with missing types
Browse files Browse the repository at this point in the history
- category
- quantity
- vision prescription
  • Loading branch information
kvs-coder committed Oct 29, 2022
1 parent 7ee3437 commit b131f88
Show file tree
Hide file tree
Showing 15 changed files with 538 additions and 596 deletions.
492 changes: 62 additions & 430 deletions Sources/Decorator/Extensions+HKCategorySample.swift

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Extensions+HKCategoryValueAppleWalkingSteadinessEvent.swift
// HealthKitReporter
//
// Created by Victor Kachalov on 04.10.22.
//

import HealthKit

@available(iOS 15.0, *)
extension HKCategoryValueAppleWalkingSteadinessEvent: CustomStringConvertible {
public var description: String {
"HKCategoryValueAppleWalkingSteadinessEvent"
}
public var detail: String {
switch self {
case .initialLow:
return "Initial low"
case .initialVeryLow:
return "Initial very low"
case .repeatLow:
return "Repeat low"
case .repeatVeryLow:
return "Repeat very low"
@unknown default:
return "Unknown"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Extensions+HKCategoryValuePregnancyTestResult.swift
// HealthKitReporter
//
// Created by Victor Kachalov on 04.10.22.
//

import HealthKit

@available(iOS 15.0, *)
extension HKCategoryValuePregnancyTestResult: CustomStringConvertible {
public var description: String {
"HKCategoryValuePregnancyTestResult"
}
public var detail: String {
switch self {
case .negative:
return "Negative"
case .positive:
return "Positive"
case .indeterminate:
return "Indeterminate"
@unknown default:
return "Unknown"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// Extensions+HKCategoryValueProgesteroneTestResult.swift
// HealthKitReporter
//
// Created by Victor Kachalov on 04.10.22.
//

import HealthKit

@available(iOS 15.0, *)
extension HKCategoryValueProgesteroneTestResult: CustomStringConvertible {
public var description: String {
"HKCategoryValueProgesteroneTestResult"
}
public var detail: String {
switch self {
case .negative:
return "Negative"
case .positive:
return "Positive"
case .indeterminate:
return "Indeterminate"
@unknown default:
return "Unknown"
}
}
}
10 changes: 8 additions & 2 deletions Sources/Decorator/Extensions+HKCategoryValueSleepAnalysis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ extension HKCategoryValueSleepAnalysis: CustomStringConvertible {
switch self {
case .inBed:
return "In Bed"
case .asleep:
return "Asleep"
case .asleepUnspecified:
return "Asleep unspecified"
case .awake:
return "Awake"
case .asleepCore:
return "Asleep core"
case .asleepDeep:
return "Asleep deep"
case .asleepREM:
return "Asleep REM"
@unknown default:
return "Unknown"
}
Expand Down
34 changes: 27 additions & 7 deletions Sources/Decorator/Extensions+HKQuantitiySample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ extension HKQuantitySample: Harmonizable {
.swimmingStrokeCount,
.numberOfTimesFallen,
.inhalerUsage,
.uvExposure:
.uvExposure,
.numberOfAlcoholicBeverages:
return quantity(unit: HKUnit.count())
case .distanceCycling,
.distanceSwimming,
Expand All @@ -32,12 +33,16 @@ extension HKQuantitySample: Harmonizable {
.height,
.waistCircumference,
.walkingStepLength,
.sixMinuteWalkTestDistance:
.sixMinuteWalkTestDistance,
.runningStrideLength,
.runningVerticalOscillation,
.underwaterDepth:
return quantity(unit: HKUnit.meter())
case .heartRate,
.respiratoryRate,
.restingHeartRate,
.walkingHeartRateAverage:
.walkingHeartRateAverage,
.heartRateRecoveryOneMinute:
return quantity(unit: HKUnit.count().unitDivided(by: HKUnit.minute()))
case .basalEnergyBurned,
.activeEnergyBurned,
Expand All @@ -48,14 +53,18 @@ extension HKQuantitySample: Harmonizable {
return quantity(unit: HKUnit.kilocalorie())
}
case .basalBodyTemperature,
.bodyTemperature:
.bodyTemperature,
.appleSleepingWristTemperature,
.waterTemperature:
return quantity(unit: HKUnit.kelvin())
case .oxygenSaturation,
.bodyFatPercentage,
.walkingDoubleSupportPercentage,
.walkingAsymmetryPercentage,
.peripheralPerfusionIndex,
.bloodAlcoholContent:
.bloodAlcoholContent,
.appleWalkingSteadiness,
.atrialFibrillationBurden:
return quantity(unit: HKUnit.percent())
case .bloodPressureSystolic,
.bloodPressureDiastolic:
Expand Down Expand Up @@ -107,15 +116,18 @@ extension HKQuantitySample: Harmonizable {
.leanBodyMass:
return quantity(unit: HKUnit.gramUnit(with: .kilo))
case .appleExerciseTime,
.appleStandTime:
.appleStandTime,
.appleMoveTime,
.runningGroundContactTime:
return quantity(unit: HKUnit.second())
case .vo2Max:
return quantity(
unit: HKUnit.literUnit(with: .milli).unitDivided(by: HKUnit.gramUnit(with: .kilo).unitMultiplied(by: HKUnit.minute()))
)
case .walkingSpeed,
.stairAscentSpeed,
.stairDescentSpeed:
.stairDescentSpeed,
.runningSpeed:
return quantity(unit: HKUnit.meter().unitDivided(by: HKUnit.second()))
case .heartRateVariabilitySDNN:
return quantity(unit: HKUnit.secondUnit(with: .milli))
Expand All @@ -135,6 +147,14 @@ extension HKQuantitySample: Harmonizable {
case .environmentalAudioExposure,
.headphoneAudioExposure:
return quantity(unit: HKUnit.pascal())
case .runningPower:
if #available(iOS 16.0, *) {
return quantity(unit: HKUnit.watt())
} else {
throw HealthKitError.notAvailable(
"\(type) is not available for the current iOS"
)
}
}
}

Expand Down
34 changes: 27 additions & 7 deletions Sources/Decorator/Extensions+HKStatistics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ extension HKStatistics: Harmonizable {
.swimmingStrokeCount,
.numberOfTimesFallen,
.inhalerUsage,
.uvExposure:
.uvExposure,
.numberOfAlcoholicBeverages:
return statistics(unit: HKUnit.count())
case .distanceCycling,
.distanceSwimming,
Expand All @@ -32,12 +33,16 @@ extension HKStatistics: Harmonizable {
.height,
.waistCircumference,
.walkingStepLength,
.sixMinuteWalkTestDistance:
.sixMinuteWalkTestDistance,
.runningStrideLength,
.runningVerticalOscillation,
.underwaterDepth:
return statistics(unit: HKUnit.meter())
case .heartRate,
.respiratoryRate,
.restingHeartRate,
.walkingHeartRateAverage:
.walkingHeartRateAverage,
.heartRateRecoveryOneMinute:
return statistics(unit: HKUnit.count().unitDivided(by: HKUnit.minute()))
case .basalEnergyBurned,
.activeEnergyBurned,
Expand All @@ -48,14 +53,18 @@ extension HKStatistics: Harmonizable {
return statistics(unit: HKUnit.kilocalorie())
}
case .basalBodyTemperature,
.bodyTemperature:
.bodyTemperature,
.appleSleepingWristTemperature,
.waterTemperature:
return statistics(unit: HKUnit.kelvin())
case .oxygenSaturation,
.bodyFatPercentage,
.walkingDoubleSupportPercentage,
.walkingAsymmetryPercentage,
.peripheralPerfusionIndex,
.bloodAlcoholContent:
.bloodAlcoholContent,
.appleWalkingSteadiness,
.atrialFibrillationBurden:
return statistics(unit: HKUnit.percent())
case .bloodPressureSystolic,
.bloodPressureDiastolic:
Expand Down Expand Up @@ -107,15 +116,18 @@ extension HKStatistics: Harmonizable {
.leanBodyMass:
return statistics(unit: HKUnit.gramUnit(with: .kilo))
case .appleExerciseTime,
.appleStandTime:
.appleStandTime,
.appleMoveTime,
.runningGroundContactTime:
return statistics(unit: HKUnit.second())
case .vo2Max:
return statistics(
unit: HKUnit.literUnit(with: .milli).unitDivided(by: HKUnit.gramUnit(with: .kilo).unitMultiplied(by: HKUnit.minute()))
)
case .walkingSpeed,
.stairAscentSpeed,
.stairDescentSpeed:
.stairDescentSpeed,
.runningSpeed:
return statistics(unit: HKUnit.meter().unitDivided(by: HKUnit.second()))
case .heartRateVariabilitySDNN:
return statistics(unit: HKUnit.secondUnit(with: .milli))
Expand All @@ -135,6 +147,14 @@ extension HKStatistics: Harmonizable {
case .environmentalAudioExposure,
.headphoneAudioExposure:
return statistics(unit: HKUnit.pascal())
case .runningPower:
if #available(iOS 16.0, *) {
return statistics(unit: HKUnit.watt())
} else {
throw HealthKitError.notAvailable(
"\(type) is not available for the current iOS"
)
}
}
}

Expand Down
22 changes: 22 additions & 0 deletions Sources/Decorator/Extensions+HKVisionPrescription.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Extensions+HKVisionPrescription.swift
// HealthKitReporter
//
// Created by Victor Kachalov on 04.10.22.
//

import HealthKit

@available(iOS 16.0, *)
extension HKVisionPrescription: Harmonizable {
typealias Harmonized = VisionPrescription.Harmonized

func harmonize() throws -> Harmonized {
return Harmonized(
dateIssuedTimestamp: dateIssued.millisecondsSince1970,
expirationDateTimestamp: expirationDate?.millisecondsSince1970,
prescriptionType: VisionPrescription.PrescriptionType(prescriptionType: prescriptionType),
metadata: metadata?.compactMapValues { String(describing: $0 )}
)
}
}
25 changes: 25 additions & 0 deletions Sources/Decorator/Extensions+HKVisionPrescriptionType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Extensions+HKVisionPrescriptionType.swift
// HealthKitReporter
//
// Created by Victor Kachalov on 04.10.22.
//

import HealthKit

@available(iOS 16.0, *)
extension HKVisionPrescriptionType: CustomStringConvertible {
public var description: String {
"HKVisionPrescriptionType"
}
public var detail: String {
switch self {
case .glasses:
return "Glasses"
case .contacts:
return "Contacts"
@unknown default:
return "Unknown"
}
}
}
4 changes: 4 additions & 0 deletions Sources/Decorator/Extensions+HKWorkoutActivityType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ extension HKWorkoutActivityType: CustomStringConvertible {
return "Pickerball"
case .cooldown:
return "Cooldown"
case .swimBikeRun:
return "Swim Bike Run"
case .transition:
return "Transition"
case .other:
return "Other"
@unknown default: return "Unknown Workout"
Expand Down
Loading

0 comments on commit b131f88

Please sign in to comment.