Skip to content

Commit a7e099a

Browse files
committed
ECG with voltage measurements
1 parent ee2005b commit a7e099a

File tree

16 files changed

+371
-165
lines changed

16 files changed

+371
-165
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [1.6.4] - 17.04.2022.
2+
3+
* ECG with Voltage measurements in one query
4+
15
## [1.6.3] - 16.04.2022.
26

37
* add from dictionary static factory for WorkoutRoute

Example/HealthKitReporter.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = "<group>"; };
5656
7003F1C7C75718FEDF8637AF /* Pods-HealthKitReporter_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HealthKitReporter_Tests.release.xcconfig"; path = "Target Support Files/Pods-HealthKitReporter_Tests/Pods-HealthKitReporter_Tests.release.xcconfig"; sourceTree = "<group>"; };
5757
784CB4452F8A563A8EC84C82 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
58-
8274ECC55EA5E895980E76E1 /* HealthKitReporter.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = HealthKitReporter.podspec; path = ../HealthKitReporter.podspec; sourceTree = "<group>"; };
58+
8274ECC55EA5E895980E76E1 /* HealthKitReporter.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = HealthKitReporter.podspec; path = ../HealthKitReporter.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
5959
9E025C132111D8252E831EEC /* Pods_HealthKitReporter_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HealthKitReporter_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6060
E99BA72C15D1884C0B1E5444 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
6161
/* End PBXFileReference section */
@@ -474,7 +474,7 @@
474474
GCC_WARN_UNUSED_FUNCTION = YES;
475475
GCC_WARN_UNUSED_VARIABLE = YES;
476476
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
477-
MARKETING_VERSION = 1.6.3;
477+
MARKETING_VERSION = 1.6.4;
478478
MTL_ENABLE_DEBUG_INFO = YES;
479479
ONLY_ACTIVE_ARCH = YES;
480480
SDKROOT = iphoneos;
@@ -525,7 +525,7 @@
525525
GCC_WARN_UNUSED_FUNCTION = YES;
526526
GCC_WARN_UNUSED_VARIABLE = YES;
527527
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
528-
MARKETING_VERSION = 1.6.3;
528+
MARKETING_VERSION = 1.6.4;
529529
MTL_ENABLE_DEBUG_INFO = NO;
530530
SDKROOT = iphoneos;
531531
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";

Example/HealthKitReporter/ViewController.swift

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@ class ViewController: UIViewController {
1414
@IBOutlet weak var writeButton: UIButton!
1515

1616
private var reporter: HealthKitReporter?
17-
private let typesToRead: [ObjectType] = [
18-
QuantityType.stepCount,
19-
QuantityType.heartRate,
20-
CategoryType.sleepAnalysis,
21-
QuantityType.heartRateVariabilitySDNN,
22-
SeriesType.heartbeatSeries,
23-
WorkoutType.workoutType,
24-
SeriesType.workoutRoute
25-
]
17+
private var typesToRead: [ObjectType] {
18+
var types: [ObjectType] = [
19+
QuantityType.stepCount,
20+
QuantityType.heartRate,
21+
CategoryType.sleepAnalysis,
22+
QuantityType.heartRateVariabilitySDNN,
23+
SeriesType.heartbeatSeries,
24+
WorkoutType.workoutType,
25+
SeriesType.workoutRoute,
26+
]
27+
if #available(iOS 14.0, *) {
28+
types.append(ElectrocardiogramType.electrocardiogramType)
29+
}
30+
return types
31+
}
2632
private let typesToWrite: [QuantityType] = [
2733
.stepCount
2834
]
@@ -97,7 +103,35 @@ class ViewController: UIViewController {
97103
}
98104
}
99105
@IBAction func seriesButtonTapped(_ sender: UIButton) {
100-
readRoutes()
106+
readEcgs()
107+
}
108+
109+
private func readEcgs() {
110+
let manager = reporter?.manager
111+
let reader = reporter?.reader
112+
do {
113+
if #available(iOS 14.0, *) {
114+
if let seriesQuery = try reader?.electrocardiogramQuery(
115+
predicate: predicate,
116+
resultsHandler: { samples, error in
117+
if error == nil {
118+
do {
119+
print(try samples.encoded())
120+
} catch {
121+
print(error)
122+
}
123+
} else {
124+
print(error ?? "error")
125+
}
126+
}) {
127+
manager?.executeQuery(seriesQuery)
128+
}
129+
} else {
130+
print("ecg is not available")
131+
}
132+
} catch {
133+
print(error)
134+
}
101135
}
102136

103137
private func readHrSeries() {

Example/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PODS:
2-
- HealthKitReporter (1.6.3)
3-
- HealthKitReporter/Tests (1.6.3)
2+
- HealthKitReporter (1.6.4)
3+
- HealthKitReporter/Tests (1.6.4)
44

55
DEPENDENCIES:
66
- HealthKitReporter (from `../`)
@@ -11,7 +11,7 @@ EXTERNAL SOURCES:
1111
:path: "../"
1212

1313
SPEC CHECKSUMS:
14-
HealthKitReporter: 42ebaa50989c4e4f6171b2caa3388c53519bea33
14+
HealthKitReporter: 313a822918d705beb27bdeeb5794c1afa4fe88bb
1515

1616
PODFILE CHECKSUM: 42dc208a4788fd9b7d8eebf0c62dd84606fddf4d
1717

Example/Pods/Local Podspecs/HealthKitReporter.podspec.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Manifest.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/HealthKitReporter/HealthKitReporter-Info.plist

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

HealthKitReporter.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'HealthKitReporter'
11-
s.version = '1.6.3'
11+
s.version = '1.6.4'
1212
s.summary = 'HealthKitReporter. A wrapper for HealthKit framework.'
1313
s.swift_versions = '5.3'
1414
s.description = 'Helps to write or read data from Apple Health via HealthKit framework.'

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ pod 'HealthKitReporter'
305305
or
306306

307307
```ruby
308-
pod 'HealthKitReporter', '~> 1.6.3'
308+
pod 'HealthKitReporter', '~> 1.6.4'
309309
```
310310

311311
### Swift Package Manager
@@ -315,7 +315,7 @@ To install it, simply add the following lines to your Package.swift file
315315

316316
```swift
317317
dependencies: [
318-
.package(url: "https://github.com/VictorKachalov/HealthKitReporter.git", from: "1.6.3")
318+
.package(url: "https://github.com/VictorKachalov/HealthKitReporter.git", from: "1.6.4")
319319
]
320320
```
321321

@@ -324,7 +324,7 @@ dependencies: [
324324
Add the line in your cartfile
325325

326326
```ruby
327-
github "VictorKachalov/HealthKitReporter" "1.6.3"
327+
github "VictorKachalov/HealthKitReporter" "1.6.4"
328328
```
329329

330330
## Author

Sources/Decorator/Extensions+HKElectrocardiogram.swift

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import HealthKit
99

1010
@available(iOS 14.0, *)
11-
extension HKElectrocardiogram: Harmonizable {
11+
extension HKElectrocardiogram {
1212
typealias Harmonized = Electrocardiogram.Harmonized
1313

14-
func harmonize() throws -> Harmonized {
14+
func harmonize(voltageMeasurements: [Electrocardiogram.VoltageMeasurement]) throws -> Harmonized {
1515
let averageHeartRateUnit = HKUnit.count().unitDivided(by: HKUnit.minute())
1616
guard
1717
let averageHeartRate = averageHeartRate?.doubleValue(for: averageHeartRateUnit)
@@ -28,15 +28,15 @@ extension HKElectrocardiogram: Harmonizable {
2828
"Invalid samplingFrequency value for HKElectrocardiogram"
2929
)
3030
}
31-
let classification = String(describing: self.classification)
32-
let symptomsStatus = String(describing: self.symptomsStatus)
3331
return Harmonized(
3432
averageHeartRate: averageHeartRate,
3533
averageHeartRateUnit: averageHeartRateUnit.unitString,
3634
samplingFrequency: samplingFrequency,
3735
samplingFrequencyUnit: samplingFrequencyUnit.unitString,
38-
classification: classification,
39-
symptomsStatus: symptomsStatus,
36+
classification: classification.description,
37+
symptomsStatus: symptomsStatus.description,
38+
count: numberOfVoltageMeasurements,
39+
voltageMeasurements: voltageMeasurements,
4040
metadata: metadata?.compactMapValues { String(describing: $0 )}
4141
)
4242
}
@@ -59,3 +59,45 @@ extension HKElectrocardiogram.VoltageMeasurement: Harmonizable {
5959
return Harmonized(value: voltage, unit: unit.unitString)
6060
}
6161
}
62+
// MARK: - CustomStringConvertible
63+
@available(iOS 14.0, *)
64+
extension HKElectrocardiogram.Classification: CustomStringConvertible {
65+
public var description: String {
66+
switch self {
67+
case .notSet:
68+
return "na"
69+
case .sinusRhythm:
70+
return "Sinus rhytm"
71+
case .atrialFibrillation:
72+
return "Atrial fibrillation"
73+
case .inconclusiveLowHeartRate:
74+
return "Inconclusive low heart rate"
75+
case .inconclusiveHighHeartRate:
76+
return "Inconclusive high heart rate"
77+
case .inconclusivePoorReading:
78+
return "Inconclusive poor reading"
79+
case .inconclusiveOther:
80+
return "Inconclusive other"
81+
case .unrecognized:
82+
return "Unrecognized"
83+
@unknown default:
84+
fatalError()
85+
}
86+
}
87+
}
88+
// MARK: - CustomStringConvertible
89+
@available(iOS 14.0, *)
90+
extension HKElectrocardiogram.SymptomsStatus: CustomStringConvertible {
91+
public var description: String {
92+
switch self {
93+
case .notSet:
94+
return "na"
95+
case .none:
96+
return "None"
97+
case .present:
98+
return "Present"
99+
@unknown default:
100+
fatalError()
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)