GithubHelp home page GithubHelp logo

calebmackdavenport / rn-apple-healthkit-healthrecords Goto Github PK

View Code? Open in Web Editor NEW
6.0 0.0 3.0 20 KB

Written in Obj-C. Bridge for RN to retrieve Health Records from Apple Healthkit.

Home Page: https://www.npmjs.com/package/rn-apple-healthkit-healthrecords

License: MIT License

JavaScript 2.43% Objective-C 97.57%

rn-apple-healthkit-healthrecords's Introduction

React Native Apple Healthkit Health Records

A React Native bridge module for interacting with Apple Healthkit's Health Records data.

Health Records version

This version only retrieves health record information from Apple Healthkit Health Records.

Simply request permission of the corresponding Health Record data you need from the list:
"Allergies", "ClinicalVitals", "Conditions", "Immunizations", "Labs", "Medications", "Procedures".
And call the associated function to retrieve the data:
getAllergyRecords, getClinicalVitalRecords, getMedicationRecords, getConditionRecords, getImmunizationRecords, getProcedureRecords, getLabRecords

Each response returns an array of arrays for each entry.
Position 0 is the name of entry, position 1 is the FHIR object.

Installation

Install the [rn-apple-healthkit-healthrecords] package from npm:

  • Run npm install rn-apple-healthkithealthrecords --save
  • Run react-native link rn-apple-healthkit-healthrecords

Update info.plist in your React Native project

<key>NSHealthShareUsageDescription</key>
<string>Read and understand health data.</string>
<key>NSHealthUpdateUsageDescription</key>
<string>Share workout data with other apps.</string>

In XCode, turn on HealthKit and ensure Clinical Health Records is enabled under the capabilities tab. Clinical Health records access requires that your account has this feature enabled.

Manual Installation

  1. Run npm install rn-apple-healthkit --save
  2. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  3. Go to node_modulesrn-apple-healthkit and add RCTAppleHealthkit.xcodeproj
  4. In XCode, in the project navigator, select your project. Add libRCTAppleHealthkit.a to your project's Build PhasesLink Binary With Libraries
  5. Click RCTAppleHealthkit.xcodeproj in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic'). In the Search Paths section, look for Header Search Paths and make sure it contains both $(SRCROOT)/../../react-native/React and $(SRCROOT)/../../../React - mark both as recursive.
  6. Enable Healthkit in your application's Capabilities
  7. Compile and run

Get Started

Initialize Healthkit. This will show the Healthkit permissions prompt for any read/write permissions set in the required options object.

Due to Apple's privacy model if an app user has previously denied a specific permission then they can not be prompted again for that same permission. The app user would have to go into the Apple Health app and grant the permission to your react-native app under sources tab.

For any data that is read from Healthkit the status/error is the same for both. This privacy restriction results in having no knowledge of whether the permission was denied (make sure it's added to the permissions options object), or the data for the specific request was nil (ex. no steps recorded today).

If new read/write permissions are added to the options object then the app user will see the Healthkit permissions prompt with the new permissions to allow.

Sample excerpt

initHealthKit requires an options object with Healthkit permission settings

import AppleHealthKit from 'rn-apple-healthkit-healthrecords';
const PERMS = AppleHealthKit.Constants.Permissions;

let options = {
  permissions: {
      read: [ "Allergies", "ClinicalVitals", "Conditions", "Immunizations", "Labs", "Medications", "Procedures", ],
  }
 };
 
AppleHealthKit.initHealthKit(options: Object, (err: string, results: Object) => {
    if (err) {
        console.log("error initializing Healthkit: ", err);
        return;
    }

    AppleHealthKit.getAllergyRecords(null, (err, allergies) => {
        if (this._handleHealthkitError(err, 'allergies')) {
          console.log('err', err)
          return;
        }
        console.log(allergies[0])
    }

 });
/* Output for Apple Health example patient with a peanut allergy */
[
  displayName: "Peanuts",
  FHIRResource: 
  {
    "id": "2",
    "resourceType": "AllergyIntolerance",
    "substance": {
      "text": "Peanuts",
      "coding": [{
        "system": "http://snomed.info/sct",
        "code": "256349002"
      }]
    },
    "recordedDate": "2015-02-18",
    "patient": {
      "display": "Candace Salinas",
      "reference": "Patient/1"
    },
    "reaction": [{
      "manifestation": [{
        "text": "Wheezing"
      }],
      "severity": "severe"
    }]
  }
]

References

rn-apple-healthkit-healthrecords's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

rn-apple-healthkit-healthrecords's Issues

Is the method `checkPermission` still in progress?

First off, thanks for this great library! I've been looking to play with HealthKit records and this helps a lot!

I see in RCTAppleHealthKit.h there is a method checkPermission defined. Is this feature still in progress?

If so, could it accept a set of permission types similar to initializeHealthKit? (Currently it looks like it will accept only a string)

Again, thanks for this project!

Cannot get health records

Printing the AppleHealthKit object outputs this.
{"Constants": {"Permissions": {"ActiveEnergyBurned": "ActiveEnergyBurned", "Allergies": "Allergies", "ClinicalVitals": "ClinicalVitals", "Conditions": "Conditions", "Immunizations": "Immunizations", "Labs": "Labs", "Medications": "Medications", "Procedures": "Procedures"}}, "authorizationStatusForType": [Function fn], "getActiveEnergyBurned": [Function fn], "getActiveEnergyDailySamples": [Function fn], "getBasalEnergyBurned": [Function fn], "getBasalEnergyDailySamples": [Function fn], "getBiologicalSex": [Function fn], "getBloodGlucoseSamples": [Function fn], "getBloodPressureSamples": [Function fn], "getBodyFatPercentageSamples": [Function fn], "getBodyTemperatureSamples": [Function fn], "getConstants": [Function anonymous], "getDailyDistanceCyclingSamples": [Function fn], "getDailyDistanceSwimmingSamples": [Function fn], "getDailyDistanceWalkingRunningSamples": [Function fn], "getDailyFlightsClimbedSamples": [Function fn], "getDailyStepCountSamples": [Function fn], "getDateOfBirth": [Function fn], "getDistanceCycling": [Function fn], "getDistanceWalkingRunning": [Function fn], "getFlightsClimbed": [Function fn], "getHeartRateSamples": [Function fn], "getHeightSamples": [Function fn], "getInfo": [Function fn], "getLatestBmi": [Function fn], "getLatestBodyFatPercentage": [Function fn], "getLatestHeight": [Function fn], "getLatestLeanBodyMass": [Function fn], "getLatestWeight": [Function fn], "getLeanBodyMassSamples": [Function fn], "getRespiratoryRateSamples": [Function fn], "getSamples": [Function fn], "getSleepSamples": [Function fn], "getStepCount": [Function fn], "getWeightSamples": [Function fn], "initHealthKit": [Function fn], "initStepCountObserver": [Function fn], "isAvailable": [Function fn], "saveBmi": [Function fn], "saveBodyFatPercentage": [Function fn], "saveFood": [Function fn], "saveHeight": [Function fn], "saveLeanBodyMass": [Function fn], "saveMindfulSession": [Function fn], "saveSteps": [Function fn], "saveWater": [Function fn], "saveWeight": [Function fn], "setObserver": [Function fn]}

Permissions are there. But cannot see .getAllergyRecords , or newer methods.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.