npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-rook-health-connect

v0.6.3

Published

test

Downloads

33

Readme

SDK Health Connect in React Native

Steps to integrate Health Connect Data extraction and transmission into your app.

Content

  1. Installation

  2. Configuration

  3. Package usage

    1. useRookHCBody
    2. useRookHCPermissions
    3. useRookHCPhysical
    4. useRookHCSleep
    5. useRookHCEvents

Installation

To build a project using the Rook Health Connect in React native you need to use at least react v16 and react native v65. This SDK is only available on Android this means that it won't work with iOS.

  1. Install the dependencies

npm

npm i react-native-rook-health-connect

yarn

yarn add react-native-rook-health-connect

Configuration

Add your client uuid in order to be authorized, follow the next example, add at the top level of your tree components the RookConnectProvider, password refers to the secret key.

import {RookConnectProvider} from 'rook_auth';

const App => () {
  return (
    <RookConnectProvider
      keys={{
        clientUUID: 'YOUR-CLIENT-UUID',
        environment: "sandbox | production",
        password: 'YOUR-PASSWORD',
      }}>
      <YourComponents />
    </RookConnectProvider>
  );
}

Then we need to configure the android project. open the android project inside android studio. We need to modify the AndroidManifest.xml file at the top level paste the next permissions in order to access to the Health connection records.

We need to add inside your activity tag an intent filter to open Health Connect APP

<intent-filter>
  <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
</intent-filter>

Your AndroidManifest.xml file should look like this

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    ...

    <application
      ...>
      <activity
        ...>
        <intent-filter>
            ...
        </intent-filter>

          <!-- For supported versions through Android 13, create an activity to show the rationale
        of Health Connect permissions once users click the privacy policy link. -->
          <intent-filter>
              <action android:name="androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE" />
          </intent-filter>
      </activity>

      <!-- For versions starting Android 14, create an activity alias to show the rationale
     of Health Connect permissions once users click the privacy policy link. -->
      <activity-alias
        android:name="ViewPermissionUsageActivity"
        android:exported="true"
        android:permission="android.permission.START_VIEW_PERMISSION_USAGE"
        android:targetActivity=".MainActivity">

        <intent-filter>
          <action android:name="android.intent.action.VIEW_PERMISSION_USAGE" />
          <category android:name="android.intent.category.HEALTH_PERMISSIONS" />
        </intent-filter>
      </activity-alias>
    </application>
</manifest>

Into the same file we need to set the minSdkVersion and targetSdkVerion

android {
  ...
  minSdkVersion: 26
  targetSdkVersion 33
  ...
}

Package usage

useRookHCBody

Definition

If you need more details about BodySummary please use right click an Go to definition to se the whole definition

type BodyProps = {
  userID: string;
};

const useRookHCBody: ({ userID }: BodyProps) => RookHCBody;

interface RookHCBody {
  getBodySummaryLastDate: () => Promise<string>;
  hasBodyPermissions: () => Promise<boolean>;
  requestBodyPermissions: () => Promise<void>;
  getBodySummary: (date: string) => Promise<BodySummary>;
}
  • getBodySummaryLastDate: Check the last date when you fetch data of body data
  • hasBodyPermissions: Return a boolean showing if body data are allowed
  • requestBodyPermissions: Request permissions only for body data
  • getBodySummary: Fetch body summary, the date should be in format YYYY-MM-DD

NOTE: The date should be formatted as YYYY-MM-DD

Example

import React, { useState } from 'react';
import { View, Text, Button, TextInput } from 'react-native';
import { useRookHCBody } from 'rook_health_connect';

export const BodyExample = () => {
  const [date, setDate] = useState('');
  const [data, setData] = useState('{}');

  const {
    getBodySummaryLastDate,
    hasBodyPermissions,
    requestBodyPermissions,
    getBodySummary,
  } = useRookHCBody({
    userID: 'YOUR-USER-ID',
  });

  const handleLastDate = async (): Promise<void> => {
    try {
      const result = await getBodySummaryLastDate();
      setData(result);
    } catch (error) {
      setData(`${error}`);
    }
  };

  const handlePermissions = async (): Promise<void> => {
    try {
      const result = await hasBodyPermissions();
      setData(`hasPermissions ${result}`);
    } catch (error) {
      setData(`${error}`);
    }
  };

  const handleRequestPermissions = async (): Promise<void> => {
    try {
      await requestBodyPermissions();
    } catch (error) {
      setData(`${error}`);
    }
  };

  const handleSummary = async (): Promise<void> => {
    try {
      // The date should be in the format YYYY-MM-DD
      const r = await getBodySummary(date);
      setData(JSON.stringify(r));
    } catch (error) {
      setData(`${error}`);
    }
  };

  return (
    <View>
      <Text>body</Text>
      <TextInput
        placeholder="YYYY-MM-DD"
        onChangeText={(text) => setDate(text)}
      />
      <Button title="last Date" onPress={handleLastDate} />
      <Button title="hasAllPermissions" onPress={handlePermissions} />
      <Button
        title="requestAllPermissions"
        onPress={handleRequestPermissions}
      />
      <Button title="get summary" onPress={handleSummary} />
      <Text>{data}</Text>
    </View>
  );
};

useRookHCPermissions

Definition

type PermissionsProps = {
  userID: string;
};

const useRookHCPermissions: ({ userID }: PermissionsProps) => RookHCPermissions;

interface RookHCPermissions {
  checkAvailability: () => Promise<AvailabilityStatus>;
  getUserTimeZone: () => Promise<UserTimeZone>;
  hasAllPermissions: () => Promise<boolean>;
  requestPermissions: () => Promise<void>;
  openHealthConnectSettings: () => Promise<void>;
}

type AvailabilityStatus = 'INSTALLED' | 'NOT_INSTALLED' | 'NOT_SUPPORTED';
  • checkAvailability: Checks if the health connect service is supported

Return

  • AvailabilityStatus means if health connect services are available in the device

    • INSTALLED means health connect services are available
    • NOT_INSTALLED means health connect services are available but is necessary to install the health connect app into the device
    • NOT_SUPPORTED means health connect services are not available
  • getUserTimeZone : Get the user time zone

  • hasAllPermissions: Check if the you already request all health connect permissions

  • requestPermissions: Request all health connect permissions

  • openHealthConnectSettings: Open the health connect settings

Example

import React, { useState } from 'react';
import { View, Text, Button } from 'react-native';
import { useRookHCPermissions } from 'rook_health_connect';

export const PermissionsExample = () => {
  const [data, setData] = useState('');

  const {
    checkAvailability,
    hasAllPermissions,
    requestPermissions,
    openHealthConnectSettings,
  } = useRookHCPermissions({ userID: 'YOUR-USER-ID' });

  const handleAvailability = async (): Promise<void> => {
    try {
      const result = await checkAvailability();
      setData(result);
    } catch (error) {
      setData(`${error}`);
    }
  };

  const handlePermissions = async (): Promise<void> => {
    try {
      const result = await hasAllPermissions();
      setData(`has permissions ${result}`);
    } catch (error) {
      setData(`${error}`);
    }
  };

  const handleRequestPermissions = async (): Promise<void> => {
    try {
      await requestPermissions();
    } catch (error) {
      setData(`${error}`);
    }
  };

  const handleOpen = async (): Promise<void> => {
    try {
      await openHealthConnectSettings();
    } catch (error) {
      setData(`${error}`);
    }
  };

  return (
    <View>
      <Text>Hola</Text>
      <Button title="Availability" onPress={handleAvailability} />
      <Button title="hasAllPermissions" onPress={handlePermissions} />
      <Button
        title="requestAllPermissions"
        onPress={handleRequestPermissions}
      />
      <Button title="openHC" onPress={handleOpen} />
      <Text>{data}</Text>
    </View>
  );
};

useRookHCPhysical

Definition

If you need more details about PhysicalSummary or PhysicalEvents please use right click an Go to definition to se the whole definition

type PhysicalProps = {
  userID: string;
};

const useRookHCPhysical: ({ userID }: PhysicalProps) => RookHCPhysical;

interface RookHCPhysical {
  getPhysicalSummaryLastDate: () => Promise<string>;
  getPhysicalEventsLastDate: () => Promise<string>;
  hasPhysicalPermissions: () => Promise<boolean>;
  requestPhysicalPermissions: () => Promise<void>;
  getPhysicalSummary: (date: string) => Promise<PhysicalSummary>;
  getPhysicalEvents: (date: string) => Promise<PhysicalEvent[]>;
}
  • getPhysicalSummaryLastDate: Check the last date when you fetch data of physical summary
  • getPhysicalEventsLastDate: Check the last date when you fetch data of physical events
  • hasPhysicalPermissions: Return a boolean showing if physical data are allowed
  • requestPhysicalPermissions: Request permissions only for physical data
  • getPhysicalSummary: Fetch physical summary, the date should be in format YYYY-MM-DD
  • getPhysicalEvents: Fetch physical events, the date should be in format YYYY-MM-DD

NOTE: The date should be formatted as YYYY-MM-DD

Example

import React, { useState } from 'react';
import { View, Text, Button, TextInput } from 'react-native';
import { useRookHCPhysical } from 'rook_health_connect';

export const PhysicalView = () => {
  const [data, setData] = useState('{}');
  const [date, setDate] = useState('');

  const {
    getPhysicalSummaryLastDate,
    getPhysicalEventsLastDate,
    hasPhysicalPermissions,
    requestPhysicalPermissions,
    getPhysicalSummary,
    getPhysicalEvents,
  } = useRookHCPhysical({ userID: 'YOUR-USER-ID' });

  const handleLastDate = async (): Promise<void> => {
    try {
      const result = await getPhysicalSummaryLastDate();
      setData(result);
    } catch (error) {
      setData(`${error}`);
    }
  };

  const handleLastDateEvent = async (): Promise<void> => {
    try {
      const result = await getPhysicalEventsLastDate();
      setData(result);
    } catch (error) {
      setData(`${error}`);
    }
  };

  const handlePermissions = async (): Promise<void> => {
    try {
      const result = await hasPhysicalPermissions();
      setData(`hasPermissions ${result}`);
    } catch (error) {
      setData(`${error}`);
    }
  };

  const handleRequestPermissions = async (): Promise<void> => {
    try {
      await requestPhysicalPermissions();
    } catch (error) {
      setData(`${error}`);
    }
  };

  const handleSummary = async (): Promise<void> => {
    try {
      const r = await getPhysicalSummary(date);
      setData(JSON.stringify(r));
    } catch (error) {
      setData(`${error}`);
    }
  };

  const handleEventSummary = async (): Promise<void> => {
    try {
      const r = await getPhysicalEvents(date);
      setData(JSON.stringify(r));
    } catch (error) {
      setData(`${error}`);
    }
  };

  return (
    <View>
      <Text>Physical</Text>
      <TextInput
        placeholder="YYYY-MM-DD"
        onChangeText={(text) => setDate(text)}
      />
      <Button title="last Date" onPress={handleLastDate} />
      <Button title="last Date event" onPress={handleLastDateEvent} />
      <Button title="hasAllPermissions" onPress={handlePermissions} />
      <Button
        title="requestAllPermissions"
        onPress={handleRequestPermissions}
      />
      <Button title="get summary" onPress={handleSummary} />
      <Button title="get summary event" onPress={handleEventSummary} />
      <Text>{data}</Text>
    </View>
  );
};

useRookHCSleep

Definition

If you need more details about SleepSummary please use right click an Go to definition to se the whole definition

type SleepProps = {
  userID: string;
};

const useRookHCSleep: ({ userID }: SleepProps) => RookHCSleep;

interface RookHCSleep {
  getSleepSummaryLastDate: () => Promise<string>;
  hasSleepPermissions: () => Promise<boolean>;
  requestSleepPermissions: () => Promise<void>;
  getSleepSummary: (date: string) => Promise<SleepSummary>;
}
  • getSleepSummaryLastDate: Check the last date when you fetch data of sleep data
  • hasSleepPermissions: Return a boolean showing if sleep data are allowed
  • requestSleepPermissions: Request permissions only for sleep data
  • getSleepSummary: Fetch sleep summary, the date should be in format YYYY-MM-DD

NOTE: The date should be formatted as YYYY-MM-DD

Example

import React, { useState } from 'react';
import { View, Text, Button, TextInput } from 'react-native';
import { useRookHCSleep } from 'rook_health_connect';

export const SleepView = () => {
  const [date, setDate] = useState('');
  const [data, setData] = useState('{}');

  const {
    getSleepSummaryLastDate,
    hasSleepPermissions,
    requestSleepPermissions,
    getSleepSummary,
  } = useRookHCSleep({ userID: 'YOUR-USER-ID' });

  const handleLastDate = async (): Promise<void> => {
    try {
      const result = await getSleepSummaryLastDate();
      setData(result);
    } catch (error) {
      setData(`${error}`);
    }
  };

  const handlePermissions = async (): Promise<void> => {
    try {
      const result = await hasSleepPermissions();
      setData(`hasPermissions ${result}`);
    } catch (error) {
      setData(`${error}`);
    }
  };

  const handleRequestPermissions = async (): Promise<void> => {
    try {
      await requestSleepPermissions();
    } catch (error) {
      setData(`${error}`);
    }
  };

  const handleSummary = async (): Promise<void> => {
    try {
      const r = await getSleepSummary(date);
      setData(JSON.stringify(r));
    } catch (error) {
      setData(`${error}`);
    }
  };

  return (
    <View>
      <Text>sleep</Text>
      <TextInput
        placeholder="YYYY-MM-DD"
        onChangeText={(text) => setDate(text)}
      />
      <Button title="last Date" onPress={handleLastDate} />
      <Button title="hasAllPermissions" onPress={handlePermissions} />
      <Button
        title="requestAllPermissions"
        onPress={handleRequestPermissions}
      />
      <Button title="get summary" onPress={handleSummary} />
      <Text>{data}</Text>
    </View>
  );
};

useRookHCEvents

Definition

If you need more details about the data that returns each event please use right click an Go to definition to se the whole definition

type EventsProps = {
  userID: string;
};

const useRookHCEvents: ({ userID }: EventsProps) => RookHCEvents;

interface RookHCEvents {
  getBodyBloodGlucoseEvents: (date: string) => Promise<HCBloodGlucoseEvent>;
  getBodyBloodPressureEvents: (date: string) => Promise<HCBloodPressureEvent>;
  getBodyMetricsEvents: (date: string) => Promise<HCBodyMetricsEvent>;
  getBodyHeartRateEvents: (date: string) => Promise<HCHeartRateEvent>;
  getBodyHydrationEvents: (date: string) => Promise<HCHydrationEvent>;
  getBodyNutritionEvents: (date: string) => Promise<HCNutritionEvent>;
  getBodyOxygenationEvents: (date: string) => Promise<HCOxygenationEvent>;
  getBodyTemperatureEvents: (date: string) => Promise<HCTemperatureEvent>;
}
  • getBodyBloodGlucoseEvents: Fetch events of blood glucose, the date should be in format YYYY-MM-DD
  • getBodyBloodPressureEvents: Fetch events of blood pressure, the date should be in format YYYY-MM-DD
  • getBodyMetricsEvents: Fetch events of body metrics like height, weight, bmi and others, the date should be in format YYYY-MM-DD
  • getBodyHeartRateEvents: Fetch events of heart rate, the date should be in format YYYY-MM-DD
  • getBodyHydrationEvents: Fetch events of hydration, the date should be in format YYYY-MM-DD
  • getBodyNutritionEvents: Fetch events of nutrition like calories, protein, fat, alcohol in take, the date should be in format YYYY-MM-DD
  • getBodyOxygenationEvents: Fetch events of oxygenation, the date should be in format YYYY-MM-DD
  • getBodyTemperatureEvents: Fetch events of body temperature, the date should be in format YYYY-MM-DD

NOTE: The date should be formatted as YYYY-MM-DD

Example

import React, { useState } from 'react';
import { Text, Button, ScrollView } from 'react-native';
import { useRookHCEvents } from 'react-native-rook-health-connect';

export const EventsView = () => {
  const {
    getBodyBloodGlucoseEvents,
    getBodyBloodPressureEvents,
    getBodyMetricsEvents,
    getBodyHeartRateEvents,
    getBodyHydrationEvents,
    getBodyNutritionEvents,
    getBodyOxygenationEvents,
    getBodyTemperatureEvents,
  } = useRookHCEvents({ userID: 'YOUR-USER-ID' });

  const [date, setDate] = useState('');

  const handlePress = async (): Promise<void> => {
    try {
      const result = await getBodyBloodGlucoseEvents(date);
      console.log(result);
    } catch (error) {
      console.log(error);
    }
  };

  const handlePressureEvent = async (): Promise<void> => {
    try {
      const result = await getBodyBloodPressureEvents(date);
      console.log(result);
    } catch (error) {
      console.log(error);
    }
  };

  const handleBodyMetricsEvent = async (): Promise<void> => {
    try {
      const result = await getBodyMetricsEvents(date);
      console.log(result);
    } catch (error) {
      console.log(error);
    }
  };

  const handleBodyHeartRateEvents = async (): Promise<void> => {
    try {
      const result = await getBodyHeartRateEvents(date);
      console.log(result);
    } catch (error) {
      console.log(error);
    }
  };

  const handleBodyHydrationEvents = async (): Promise<void> => {
    try {
      const result = await getBodyHydrationEvents(date);
      console.log(result);
    } catch (error) {
      console.log(error);
    }
  };

  const handleBodyNutritionEvents = async (): Promise<void> => {
    try {
      const result = await getBodyNutritionEvents(date);
      console.log(result);
    } catch (error) {
      console.log(error);
    }
  };

  const handleBodyOxygenationEvents = async (): Promise<void> => {
    try {
      const result = await getBodyOxygenationEvents(date);
      console.log(result);
    } catch (error) {
      console.log(error);
    }
  };

  const handlePhysicalTemperatureEvents = async (): Promise<void> => {
    try {
      const result = await getBodyTemperatureEvents(date);
      console.log(result);
    } catch (error) {
      console.log(error);
    }
  };

  return (
    <ScrollView>
      <Text>Events</Text>
      <TextInput
        placeholder="YYYY-MM-DD"
        onChangeText={(text) => setDate(text)}
      />
      <Button title="Blood Glucose Event" onPress={handlePress} />
      <Button title="Blood Pressure Event" onPress={handlePressureEvent} />
      <Button title="Body Metrics Event" onPress={handleBodyMetricsEvent} />
      <Button
        title="Body HeartRate Event"
        onPress={handleBodyHeartRateEvents}
      />
      <Button title="Hydration Events" onPress={handleBodyHydrationEvents} />
      <Button title="Nutrition Events" onPress={handleBodyNutritionEvents} />
      <Button
        title="Oxygenation Events"
        onPress={handleBodyOxygenationEvents}
      />
      <Button
        title="Temperature Events"
        onPress={handlePhysicalTemperatureEvents}
      />
    </ScrollView>
  );
};