Skip to content

Commit

Permalink
2.0.4 preparations
Browse files Browse the repository at this point in the history
save Correlation in the health repository
  • Loading branch information
victor kachalov committed May 27, 2022
1 parent 7e7b6a4 commit 71d696d
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [2.0.4] - 27.05.2022

* Add Correlation samples writing

## [2.0.3] - 18.04.2022

* ECG with Voltage measurements in one query on demand
Expand Down
8 changes: 4 additions & 4 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ PODS:
- Flutter (1.0.0)
- flutter_local_notifications (0.0.1):
- Flutter
- health_kit_reporter (1.5.2):
- health_kit_reporter (2.0.4):
- Flutter
- HealthKitReporter
- HealthKitReporter (1.6.5)
- HealthKitReporter (1.6.9)

DEPENDENCIES:
- Flutter (from `Flutter`)
Expand All @@ -27,8 +27,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
flutter_local_notifications: 0c0b1ae97e741e1521e4c1629a459d04b9aec743
health_kit_reporter: 6da8c20414d6a53cf2babcfd0314ea05a943bd3e
HealthKitReporter: cec816c8f9477c8a0a8e2f90dd7aa0780bf21e16
health_kit_reporter: d88d6d571215f7eaf4dc7412e551e139080681cd
HealthKitReporter: 655b234e8e6e6097fe5f05c27e67df5a99771501

PODFILE CHECKSUM: a75497545d4391e2d394c3668e20cfb1c2bbd4aa

Expand Down
46 changes: 46 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:health_kit_reporter/health_kit_reporter.dart';
import 'package:health_kit_reporter/model/payload/category.dart';
import 'package:health_kit_reporter/model/payload/correlation.dart';
import 'package:health_kit_reporter/model/payload/date_components.dart';
import 'package:health_kit_reporter/model/payload/device.dart';
import 'package:health_kit_reporter/model/payload/preferred_unit.dart';
Expand Down Expand Up @@ -152,6 +153,9 @@ class _MyAppState extends State<MyApp> {
WorkoutType.workoutType.identifier,
CategoryType.sleepAnalysis.identifier,
CategoryType.mindfulSession.identifier,
QuantityType.bloodPressureDiastolic.identifier,
QuantityType.bloodPressureSystolic.identifier,
//CorrelationType.bloodPressure.identifier,
];
final isRequested =
await HealthKitReporter.requestAuthorization(readTypes, writeTypes);
Expand Down Expand Up @@ -381,6 +385,12 @@ class _WriteView extends StatelessWidget with HealthKitReporterMixin {
},
child: Text('saveMindfulMinutes'),
),
TextButton(
onPressed: () {
saveBloodPressureCorrelation();
},
child: Text('saveBloodPressureCorrelation'),
),
],
);
}
Expand Down Expand Up @@ -495,6 +505,42 @@ class _WriteView extends StatelessWidget with HealthKitReporterMixin {
print(e);
}
}

void saveBloodPressureCorrelation() async {
try {
final now = DateTime.now();
final minuteAgo = now.add(Duration(minutes: -1));
final sys = Quantity(
'testSysUUID234',
QuantityType.bloodPressureSystolic.identifier,
minuteAgo.millisecondsSinceEpoch,
now.millisecondsSinceEpoch,
device,
sourceRevision,
QuantityHarmonized(123, 'mmHg', null));
final dia = Quantity(
'testDiaUUID456',
QuantityType.bloodPressureDiastolic.identifier,
minuteAgo.millisecondsSinceEpoch,
now.millisecondsSinceEpoch,
device,
sourceRevision,
QuantityHarmonized(89, 'mmHg', null));
final correlationJarmonized = CorrelationHarmonized([sys, dia], [], null);
final correlation = Correlation(
'test',
CorrelationType.bloodPressure.identifier,
minuteAgo.millisecondsSinceEpoch,
now.millisecondsSinceEpoch,
device,
sourceRevision,
correlationJarmonized);
final saved = await HealthKitReporter.save(correlation);
print('BloodPressureCorrelationSaved: $saved');
} catch (e) {
print(e);
}
}
}

class _ObserveView extends StatelessWidget with HealthKitReporterMixin {
Expand Down
17 changes: 17 additions & 0 deletions ios/Classes/Extensions+SwiftHealthKitReporterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,23 @@ extension SwiftHealthKitReporterPlugin {
}
)
}
if let correlation = arguments["correlation"] as? [String: Any] {
let sample = try Correlation.make(from: correlation)
return sample.copyWith(
startTimestamp: sample.startTimestamp.secondsSince1970,
endTimestamp: sample.endTimestamp.secondsSince1970,
harmonized: sample.harmonized.copyWith(
quantitySamples: sample.harmonized.quantitySamples.map { $0.copyWith(
startTimestamp: $0.startTimestamp.secondsSince1970,
endTimestamp: $0.endTimestamp.secondsSince1970
)},
categorySamples: sample.harmonized.categorySamples.map { $0.copyWith(
startTimestamp: $0.startTimestamp.secondsSince1970,
endTimestamp: $0.endTimestamp.secondsSince1970
)}
)
)
}
throw HealthKitError.invalidValue("Invalid arguments: \(arguments)")
}
private func throwParsingArgumentsError(
Expand Down
2 changes: 1 addition & 1 deletion ios/health_kit_reporter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
Pod::Spec.new do |s|
s.name = 'health_kit_reporter'
s.version = '1.5.2'
s.version = '2.0.4'
s.summary = 'HealthKitReporter. A wrapper for HealthKit framework. A Flutter plugin'
s.swift_versions = '5.3'
s.description = 'Helps to write or read data from Apple Health via HealthKit framework using Flutter.'
Expand Down
1 change: 1 addition & 0 deletions lib/model/payload/sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ abstract class Sample<Harmonized> {
if (this is Quantity) arguments['quantity'] = map;
if (this is Category) arguments['category'] = map;
if (this is Workout) arguments['workout'] = map;
if (this is Correlation) arguments['correlation'] = map;
return arguments;
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: health_kit_reporter
description: Helps to write or read data from Apple Health via HealthKit framework.
version: 2.0.3
version: 2.0.4
homepage: https://github.com/VictorKachalov/health_kit_reporter

environment:
Expand Down
216 changes: 216 additions & 0 deletions test/correlation_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:health_kit_reporter/model/payload/correlation.dart';

void main() {
test('correlation_parse_from_json', () {
final json = {
"device": {
"manufacturer": "Guy",
"softwareVersion": "some_2",
"model": "6.1.1",
"localIdentifier": "some_3",
"firmwareVersion": "some_1",
"udiDeviceIdentifier": "some_4",
"name": "Guy's iPhone",
"hardwareVersion": "some_0"
},
"sourceRevision": {
"productType": "CocoaPod",
"systemVersion": "1.0.0.0",
"source": {
"name": "mySource",
"bundleIdentifier": "com.kvs.hkreporter"
},
"operatingSystem": {
"majorVersion": 1,
"minorVersion": 1,
"patchVersion": 1
},
"version": "1.0.0"
},
"uuid": "BA0ADD39-638C-4FF8-AF48-0FC88CDCC48A",
"identifier": "HKCorrelationTypeIdentifierBloodPressure",
"startTimestamp": 1653657145.998812,
"endTimestamp": 1653657205.998812,
"harmonized": {
"metadata": {"you": "saved it"},
"categorySamples": [],
"quantitySamples": [
{
"device": {
"manufacturer": "Guy",
"softwareVersion": "some_2",
"model": "6.1.1",
"localIdentifier": "some_3",
"firmwareVersion": "some_1",
"udiDeviceIdentifier": "some_4",
"name": "Guy's iPhone",
"hardwareVersion": "some_0"
},
"sourceRevision": {
"productType": "CocoaPod",
"systemVersion": "1.0.0.0",
"source": {
"name": "mySource",
"bundleIdentifier": "com.kvs.hkreporter"
},
"operatingSystem": {
"majorVersion": 1,
"minorVersion": 1,
"patchVersion": 1
},
"version": "1.0.0"
},
"uuid": "52DC2FFB-D361-4CDC-9450-29EFEBD1BD94",
"identifier": "HKQuantityTypeIdentifierBloodPressureSystolic",
"startTimestamp": 1653657145.998812,
"endTimestamp": 1653657205.998812,
"harmonized": {
"value": 123,
"metadata": {"you": "saved it"},
"unit": "mmHg"
}
},
{
"device": {
"manufacturer": "Guy",
"softwareVersion": "some_2",
"model": "6.1.1",
"localIdentifier": "some_3",
"firmwareVersion": "some_1",
"udiDeviceIdentifier": "some_4",
"name": "Guy's iPhone",
"hardwareVersion": "some_0"
},
"sourceRevision": {
"productType": "CocoaPod",
"systemVersion": "1.0.0.0",
"source": {
"name": "mySource",
"bundleIdentifier": "com.kvs.hkreporter"
},
"operatingSystem": {
"majorVersion": 1,
"minorVersion": 1,
"patchVersion": 1
},
"version": "1.0.0"
},
"uuid": "3850F06E-383B-476A-BFCC-4A6DF979CFAE",
"identifier": "HKQuantityTypeIdentifierBloodPressureDiastolic",
"startTimestamp": 1653657145.998812,
"endTimestamp": 1653657205.998812,
"harmonized": {
"value": 83,
"metadata": {"you": "saved it"},
"unit": "mmHg"
}
}
]
}
};
final sut = Correlation.fromJson(json);
expect(sut.identifier, "HKCorrelationTypeIdentifierBloodPressure");
expect(sut.startTimestamp, 1653657145.998812);
expect(sut.endTimestamp, 1653657205.998812);
expect(sut.device?.name, "Guy's iPhone");
expect(sut.device?.manufacturer, "Guy");
expect(sut.device?.model, "6.1.1");
expect(sut.device?.hardwareVersion, "some_0");
expect(sut.device?.firmwareVersion, "some_1");
expect(sut.device?.softwareVersion, "some_2");
expect(sut.device?.localIdentifier, "some_3");
expect(sut.device?.udiDeviceIdentifier, "some_4");
expect(sut.sourceRevision.source.name, "mySource");
expect(sut.sourceRevision.source.bundleIdentifier, "com.kvs.hkreporter");
expect(sut.sourceRevision.version, "1.0.0");
expect(sut.sourceRevision.productType, "CocoaPod");
expect(sut.sourceRevision.systemVersion, "1.0.0.0");
expect(sut.sourceRevision.operatingSystem.majorVersion, 1);
expect(sut.sourceRevision.operatingSystem.minorVersion, 1);
expect(sut.sourceRevision.operatingSystem.patchVersion, 1);
expect(sut.harmonized.quantitySamples.length, 2);
expect(sut.harmonized.quantitySamples[0].identifier,
"HKQuantityTypeIdentifierBloodPressureSystolic");
expect(sut.harmonized.quantitySamples[0].startTimestamp, 1653657145.998812);
expect(sut.harmonized.quantitySamples[0].endTimestamp, 1653657205.998812);
expect(sut.harmonized.quantitySamples[0].device?.name, "Guy's iPhone");
expect(sut.harmonized.quantitySamples[0].device?.manufacturer, "Guy");
expect(sut.harmonized.quantitySamples[0].device?.model, "6.1.1");
expect(sut.harmonized.quantitySamples[0].device?.hardwareVersion, "some_0");
expect(sut.harmonized.quantitySamples[0].device?.firmwareVersion, "some_1");
expect(sut.harmonized.quantitySamples[0].device?.softwareVersion, "some_2");
expect(sut.harmonized.quantitySamples[0].device?.localIdentifier, "some_3");
expect(sut.harmonized.quantitySamples[0].device?.udiDeviceIdentifier,
"some_4");
expect(sut.harmonized.quantitySamples[0].sourceRevision.source.name,
"mySource");
expect(
sut.harmonized.quantitySamples[0].sourceRevision.source
.bundleIdentifier,
"com.kvs.hkreporter");
expect(sut.harmonized.quantitySamples[0].sourceRevision.version, "1.0.0");
expect(sut.harmonized.quantitySamples[0].sourceRevision.productType,
"CocoaPod");
expect(sut.harmonized.quantitySamples[0].sourceRevision.systemVersion,
"1.0.0.0");
expect(
sut.harmonized.quantitySamples[0].sourceRevision.operatingSystem
.majorVersion,
1);
expect(
sut.harmonized.quantitySamples[0].sourceRevision.operatingSystem
.minorVersion,
1);
expect(
sut.harmonized.quantitySamples[0].sourceRevision.operatingSystem
.patchVersion,
1);
expect(sut.harmonized.quantitySamples[0].harmonized.value, 123);
expect(sut.harmonized.quantitySamples[0].harmonized.unit, "mmHg");
expect(sut.harmonized.quantitySamples[0].harmonized.metadata,
{"you": "saved it"});
expect(sut.harmonized.quantitySamples[1].identifier,
"HKQuantityTypeIdentifierBloodPressureDiastolic");
expect(sut.harmonized.quantitySamples[1].startTimestamp, 1653657145.998812);
expect(sut.harmonized.quantitySamples[1].endTimestamp, 1653657205.998812);
expect(sut.harmonized.quantitySamples[1].device?.name, "Guy's iPhone");
expect(sut.harmonized.quantitySamples[1].device?.manufacturer, "Guy");
expect(sut.harmonized.quantitySamples[1].device?.model, "6.1.1");
expect(sut.harmonized.quantitySamples[1].device?.hardwareVersion, "some_0");
expect(sut.harmonized.quantitySamples[1].device?.firmwareVersion, "some_1");
expect(sut.harmonized.quantitySamples[1].device?.softwareVersion, "some_2");
expect(sut.harmonized.quantitySamples[1].device?.localIdentifier, "some_3");
expect(sut.harmonized.quantitySamples[1].device?.udiDeviceIdentifier,
"some_4");
expect(sut.harmonized.quantitySamples[1].sourceRevision.source.name,
"mySource");
expect(
sut.harmonized.quantitySamples[1].sourceRevision.source
.bundleIdentifier,
"com.kvs.hkreporter");
expect(sut.harmonized.quantitySamples[1].sourceRevision.version, "1.0.0");
expect(sut.harmonized.quantitySamples[1].sourceRevision.productType,
"CocoaPod");
expect(sut.harmonized.quantitySamples[1].sourceRevision.systemVersion,
"1.0.0.0");
expect(
sut.harmonized.quantitySamples[1].sourceRevision.operatingSystem
.majorVersion,
1);
expect(
sut.harmonized.quantitySamples[1].sourceRevision.operatingSystem
.minorVersion,
1);
expect(
sut.harmonized.quantitySamples[1].sourceRevision.operatingSystem
.patchVersion,
1);
expect(sut.harmonized.quantitySamples[1].harmonized.value, 83);
expect(sut.harmonized.quantitySamples[1].harmonized.unit, "mmHg");
expect(sut.harmonized.quantitySamples[1].harmonized.metadata,
{"you": "saved it"});
expect(sut.harmonized.categorySamples.length, 0);
expect(sut.harmonized.metadata, {"you": "saved it"});
});
}

0 comments on commit 71d696d

Please sign in to comment.