Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For iOS healthkit how to save systolic and diastolic blood pressure values?

Here is code for saving blood pressure data in health kit

 HKUnit *BPunit = [HKUnit millimeterOfMercuryUnit];
 HKQuantity *BPSysQuantity = [HKQuantity quantityWithUnit:BPunit doubleValue:150.0];
 HKQuantityType *BPSysType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodPressureSystolic];
 HKQuantitySample *BPSysSample = [HKQuantitySample quantitySampleWithType:BPSysType quantity:BpsysQuantity startDate:now endDate:now];
 [self.healthStore saveObject:BPSysSample withCompletion:^(BOOL success, NSError *error) 

same way for diastolic also,

But how to save both combine as single entry in health app? Currently two diffrent entries are saved for systolic and diastolic blood pressure in health app.

like image 975
Pradip Avatar asked Sep 03 '14 11:09

Pradip


People also ask

How do I record blood pressure with Apple Health?

View your health records Tap Browse at the bottom right to display the Health Categories screen, then do one of the following: Tap the search field, then enter the name of a health record category (such as clinical vitals) or a type of data (such as blood pressure).

How do I take my blood pressure on my iPhone?

Tap e.g. “Blood Pressure“ and you will get to the details page. Click the plus icon at the right top corner to add your data. Now type in your systolic (first) and diastolic (second) value into the related fields and tap the “Add“ button at the right top corner.


2 Answers

- (void)saveBloodPressureIntoHealthStore:(double)Systolic Dysbp:(double)Diastolic {

HKUnit *BloodPressureUnit = [HKUnit millimeterOfMercuryUnit];

HKQuantity *SystolicQuantity = [HKQuantity quantityWithUnit:BloodPressureUnit doubleValue:Systolic];
HKQuantity *DiastolicQuantity = [HKQuantity quantityWithUnit:BloodPressureUnit doubleValue:Diastolic];

HKQuantityType *SystolicType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodPressureSystolic];
HKQuantityType *DiastolicType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodPressureDiastolic];

NSDate *now = [NSDate date];

HKQuantitySample *SystolicSample = [HKQuantitySample quantitySampleWithType:SystolicType quantity:SystolicQuantity startDate:now endDate:now];
HKQuantitySample *DiastolicSample = [HKQuantitySample quantitySampleWithType:DiastolicType quantity:DiastolicQuantity startDate:now endDate:now];

NSSet *objects=[NSSet setWithObjects:SystolicSample,DiastolicSample, nil];
HKCorrelationType *bloodPressureType = [HKObjectType correlationTypeForIdentifier:
                                 HKCorrelationTypeIdentifierBloodPressure];
HKCorrelation *BloodPressure = [HKCorrelation correlationWithType:bloodPressureType startDate:now endDate:now objects:objects];
                                [self.healthStore saveObject:BloodPressure withCompletion:^(BOOL success, NSError *error) {
    if (!success) {
        NSLog(@"An error occured saving the height sample %@. In your app, try to handle this gracefully. The error was: %@.", BloodPressure, error);
        abort();
    }
    [_activity stopAnimating];
    UIAlertView *savealert=[[UIAlertView alloc]initWithTitle:@"HealthDemo" message:@"Blood Pressure values has been saved to Health App" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [savealert show];

}];
}
like image 82
Pradip Avatar answered Sep 22 '22 10:09

Pradip


Check out HKCorrelation. A correlation is a set of related objects and is designed to represent things like blood pressure readings and food. You can save create and save correlations just like samples and you can query for correlations using HKCorrelationQuery.

like image 29
Allan Avatar answered Sep 23 '22 10:09

Allan