-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from predictive-technology-laboratory/ios-health
Integrated HealthKit
- Loading branch information
Showing
27 changed files
with
954 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.developer.healthkit</key> | ||
<true/> | ||
</dict> | ||
</plist> |
79 changes: 79 additions & 0 deletions
79
Sensus.iOS/Probes/User/Health/iOSHealthKitBiologicalSexProbe.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2014 The Rector & Visitors of the University of Virginia | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using SensusService; | ||
using System.Threading; | ||
using HealthKit; | ||
using Foundation; | ||
using SensusService.Probes.User.Health; | ||
using Newtonsoft.Json; | ||
|
||
namespace Sensus.iOS.Probes.User.Health | ||
{ | ||
public class iOSHealthKitBiologicalSexProbe : iOSHealthKitProbe | ||
{ | ||
protected override string DefaultDisplayName | ||
{ | ||
get | ||
{ | ||
return "Biological Sex (HealthKit)"; | ||
} | ||
} | ||
|
||
public override Type DatumType | ||
{ | ||
get | ||
{ | ||
return typeof(BiologicalSexDatum); | ||
} | ||
} | ||
|
||
public override int DefaultPollingSleepDurationMS | ||
{ | ||
get | ||
{ | ||
return int.MaxValue; | ||
} | ||
} | ||
|
||
public iOSHealthKitBiologicalSexProbe() | ||
: base(HKObjectType.GetCharacteristicType(HKCharacteristicTypeIdentifierKey.BiologicalSex)) | ||
{ | ||
} | ||
|
||
protected override IEnumerable<Datum> Poll(CancellationToken cancellationToken) | ||
{ | ||
List<Datum> data = new List<Datum>(); | ||
|
||
NSError error; | ||
HKBiologicalSexObject biologicalSex = HealthStore.GetBiologicalSex(out error); | ||
|
||
if (error == null) | ||
{ | ||
if (biologicalSex.BiologicalSex == HKBiologicalSex.Female) | ||
data.Add(new BiologicalSexDatum(DateTimeOffset.Now, BiologicalSex.Female)); | ||
else if (biologicalSex.BiologicalSex == HKBiologicalSex.Male) | ||
data.Add(new BiologicalSexDatum(DateTimeOffset.Now, BiologicalSex.Male)); | ||
else if (biologicalSex.BiologicalSex == HKBiologicalSex.Other) | ||
data.Add(new BiologicalSexDatum(DateTimeOffset.Now, BiologicalSex.Other)); | ||
} | ||
else | ||
SensusServiceHelper.Get().Logger.Log("Error reading biological sex: " + error.Description, LoggingLevel.Normal, GetType()); | ||
|
||
return data; | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
Sensus.iOS/Probes/User/Health/iOSHealthKitBirthdateProbe.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2014 The Rector & Visitors of the University of Virginia | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using SensusService; | ||
using System.Threading; | ||
using HealthKit; | ||
using Foundation; | ||
using Xamarin.Forms.Platform.iOS; | ||
using Newtonsoft.Json; | ||
|
||
namespace Sensus.iOS.Probes.User.Health | ||
{ | ||
public class iOSHealthKitBirthdateProbe : iOSHealthKitProbe | ||
{ | ||
protected override string DefaultDisplayName | ||
{ | ||
get | ||
{ | ||
return "Birthdate (HealthKit)"; | ||
} | ||
} | ||
|
||
public override Type DatumType | ||
{ | ||
get | ||
{ | ||
return typeof(BirthdateDatum); | ||
} | ||
} | ||
|
||
public override int DefaultPollingSleepDurationMS | ||
{ | ||
get | ||
{ | ||
return int.MaxValue; | ||
} | ||
} | ||
|
||
public iOSHealthKitBirthdateProbe() | ||
: base(HKObjectType.GetCharacteristicType(HKCharacteristicTypeIdentifierKey.DateOfBirth)) | ||
{ | ||
} | ||
|
||
protected override IEnumerable<Datum> Poll(CancellationToken cancellationToken) | ||
{ | ||
List<Datum> data = new List<Datum>(); | ||
|
||
NSError error; | ||
NSDate dateOfBirth = HealthStore.GetDateOfBirth(out error); | ||
|
||
if (error == null) | ||
data.Add(new BirthdateDatum(DateTimeOffset.Now, new DateTimeOffset(dateOfBirth.ToDateTime()))); | ||
else | ||
SensusServiceHelper.Get().Logger.Log("Error reading date of birth: " + error.Description, LoggingLevel.Normal, GetType()); | ||
|
||
return data; | ||
} | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
Sensus.iOS/Probes/User/Health/iOSHealthKitBloodTypeProbe.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2014 The Rector & Visitors of the University of Virginia | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using HealthKit; | ||
using System.Collections.Generic; | ||
using SensusService; | ||
using System.Threading; | ||
using Foundation; | ||
using SensusService.Probes.User.Health; | ||
using Newtonsoft.Json; | ||
|
||
namespace Sensus.iOS.Probes.User.Health | ||
{ | ||
public class iOSHealthKitBloodTypeProbe : iOSHealthKitProbe | ||
{ | ||
protected override string DefaultDisplayName | ||
{ | ||
get | ||
{ | ||
return "Blood Type (HealthKit)"; | ||
} | ||
} | ||
|
||
public override Type DatumType | ||
{ | ||
get | ||
{ | ||
return typeof(BloodTypeDatum); | ||
} | ||
} | ||
|
||
public override int DefaultPollingSleepDurationMS | ||
{ | ||
get | ||
{ | ||
return int.MaxValue; | ||
} | ||
} | ||
|
||
public iOSHealthKitBloodTypeProbe() | ||
: base(HKObjectType.GetCharacteristicType(HKCharacteristicTypeIdentifierKey.BloodType)) | ||
{ | ||
} | ||
|
||
protected override IEnumerable<Datum> Poll(CancellationToken cancellationToken) | ||
{ | ||
List<Datum> data = new List<Datum>(); | ||
|
||
NSError error; | ||
HKBloodTypeObject bloodType = HealthStore.GetBloodType(out error); | ||
|
||
if (error == null) | ||
{ | ||
if (bloodType.BloodType == HKBloodType.ABNegative) | ||
data.Add(new BloodTypeDatum(DateTimeOffset.Now, BloodType.ABNegative)); | ||
else if (bloodType.BloodType == HKBloodType.ABPositive) | ||
data.Add(new BloodTypeDatum(DateTimeOffset.Now, BloodType.ABPositive)); | ||
else if (bloodType.BloodType == HKBloodType.ANegative) | ||
data.Add(new BloodTypeDatum(DateTimeOffset.Now, BloodType.ANegative)); | ||
else if (bloodType.BloodType == HKBloodType.APositive) | ||
data.Add(new BloodTypeDatum(DateTimeOffset.Now, BloodType.APositive)); | ||
else if (bloodType.BloodType == HKBloodType.BNegative) | ||
data.Add(new BloodTypeDatum(DateTimeOffset.Now, BloodType.BNegative)); | ||
else if (bloodType.BloodType == HKBloodType.BPositive) | ||
data.Add(new BloodTypeDatum(DateTimeOffset.Now, BloodType.BPositive)); | ||
else if (bloodType.BloodType == HKBloodType.ONegative) | ||
data.Add(new BloodTypeDatum(DateTimeOffset.Now, BloodType.ONegative)); | ||
else if (bloodType.BloodType == HKBloodType.OPositive) | ||
data.Add(new BloodTypeDatum(DateTimeOffset.Now, BloodType.OPositive)); | ||
} | ||
else | ||
SensusServiceHelper.Get().Logger.Log("Error reading blood type: " + error.Description, LoggingLevel.Normal, GetType()); | ||
|
||
return data; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2014 The Rector & Visitors of the University of Virginia | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System; | ||
using SensusService.Probes.User.Health; | ||
using HealthKit; | ||
using Xamarin.Forms.Platform.iOS; | ||
using SensusService; | ||
using Newtonsoft.Json; | ||
|
||
namespace Sensus.iOS.Probes.User.Health | ||
{ | ||
public class iOSHealthKitHeightProbe : iOSHealthKitSamplingProbe | ||
{ | ||
protected override string DefaultDisplayName | ||
{ | ||
get | ||
{ | ||
return "Height (HealthKit)"; | ||
} | ||
} | ||
|
||
public override Type DatumType | ||
{ | ||
get | ||
{ | ||
return typeof(HeightDatum); | ||
} | ||
} | ||
|
||
public override int DefaultPollingSleepDurationMS | ||
{ | ||
get | ||
{ | ||
return int.MaxValue; | ||
} | ||
} | ||
|
||
public iOSHealthKitHeightProbe() | ||
: base(HKObjectType.GetQuantityType(HKQuantityTypeIdentifierKey.Height)) | ||
{ | ||
} | ||
|
||
protected override Datum ConvertSampleToDatum(HKSample sample) | ||
{ | ||
HKQuantitySample quantitySample = sample as HKQuantitySample; | ||
|
||
if (quantitySample == null) | ||
return null; | ||
else | ||
return new HeightDatum(new DateTimeOffset(quantitySample.StartDate.ToDateTime()), quantitySample.Quantity.GetDoubleValue(HKUnit.Inch)); | ||
} | ||
} | ||
} |
Oops, something went wrong.