Skip to content

Commit

Permalink
feat: read docs
Browse files Browse the repository at this point in the history
  • Loading branch information
carozo committed Jan 8, 2025
1 parent df888a6 commit bd0395b
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 8 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ npm install react-native-health-link
Set up react-native-health following this instructions:

1. Install pods:

```
cd ios && pod install
```
Expand All @@ -33,14 +34,13 @@ cd ios && pod install

3. To add Healthkit support to your application's Capabilities:

- Open the ios/ folder of your project in Xcode
- Select the project name in the left sidebar
- In the main view select '+ Capability' and double click 'HealthKit'
- To enable access to clinical data types, check the Clinical Health Records box.
- Open the ios/ folder of your project in Xcode
- Select the project name in the left sidebar
- In the main view select '+ Capability' and double click 'HealthKit'
- To enable access to clinical data types, check the Clinical Health Records box.

More information on react-native-health's [official GitHub page](https://github.com/agencyenterprise/react-native-health).


### Android

#### Requeriments for react-native-health-connect
Expand All @@ -50,7 +50,7 @@ Make sure you have React Native version 0.71 or higher with the latest patch ins
- [Health Connect](https://play.google.com/store/apps/details?id=com.google.android.apps.healthdata&hl=en&gl=US) needs to be installed on the user's device. Starting from Android 14 (Upside Down Cake), Health Connect is part of the Android Framework. Read more [here](https://developer.android.com/health-and-fitness/guides/health-connect/develop/get-started#step-1).
- Health Connect API requires minSdkVersion=26 (Android Oreo / 8.0).
- If you are planning to release your app on Google Play, you will need to submit a [declaration form](https://docs.google.com/forms/d/1LFjbq1MOCZySpP5eIVkoyzXTanpcGTYQH26lKcrQUJo/viewform?edit_requested=true). Approval can take up to 7 days.
Approval does not grant you immediate access to Health Connect. A whitelist must propagate to the Health Connect servers, which take an additional 5-7 business days. The whitelist is updated every Monday according to Google Fit AHP support.
Approval does not grant you immediate access to Health Connect. A whitelist must propagate to the Health Connect servers, which take an additional 5-7 business days. The whitelist is updated every Monday according to Google Fit AHP support.

#### Setup

Expand Down Expand Up @@ -91,10 +91,8 @@ You also need to setup permissions in your `AndroidManifest.xml` file. For more

More information on react-native-health-connects's [official GitHub page](https://github.com/matinzd/react-native-health-connect).


## Usage


```jsx
import { useState } from 'react';
import { Text } from 'react-native';
Expand Down Expand Up @@ -123,6 +121,11 @@ export default function App() {

```
### Documentation
The library provides the following functions:
[read](./docs/read.md)
## Contributing
Expand Down
98 changes: 98 additions & 0 deletions docs/read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# `read` Function

The `read` function retrieves health-related data for the specified `HealthLinkDataType` using platform-specific APIs for iOS and Android. It supports filtering and sorting options through the `ReadOptions` interface.

---

## **Example usage**

```typescript
read(HealthLinkDataType.BloodGlucose, {
unit: BloodGlucoseUnit.MmolPerL,
startDate: new Date('2021-01-01').toISOString(),
});
```

## **Data types**

Type: HealthLinkDataType
Description: Specifies the type of health data to retrieve. Possible values are:

```
BloodGlucose
Height
Weight
HeartRate
RestingHeartRate
BloodPressure
OxygenSaturation
Steps
```

## **Options**

```typescript
export interface ReadOptions {
startDate?: string;
endDate?: string;
ascending?: boolean;
limit?: number;
unit?: string;
}
```

## **`ReadOptions` Interface**

The `ReadOptions` interface defines the optional parameters that can be used to filter, sort, and limit the health data retrieved.

| **Field** | **Type** | **Description** | **Default** |
| ----------- | --------- | ----------------------------------------------------------------------------------------------------- | ---------------------- |
| `startDate` | `string` | ISO 8601 string specifying the start date for filtering data. | `undefined` |
| `endDate` | `string` | ISO 8601 string specifying the end date for filtering data. | `undefined` |
| `ascending` | `boolean` | Determines if the results should be sorted in ascending order (`true`) or descending order (`false`). | `false` (descending) |
| `limit` | `number` | Limits the number of results returned. | `undefined` (no limit) |
| `unit` | `string` | The unit of measurement for the data (e.g., `BloodGlucoseUnit.MmolPerL`). | `undefined` |

---

### **Field Explanations**

1. **`startDate`**:

- Filters the data to include only records starting from this date.
- Example: `startDate: "2023-01-01T00:00:00Z"` will retrieve data from January 1, 2023.

2. **`endDate`**:

- Filters the data to include only records up to this date.
- Example: `endDate: "2023-12-31T23:59:59Z"` will retrieve data until December 31, 2023.
- If only `endDate` is provided, all data before this date will be retrieved.

3. **`ascending`**:

- Defines the sorting order of the retrieved data.
- Example: `ascending: true` will sort results in chronological order, whereas `false` will sort them in reverse chronological order.

4. **`limit`**:

- Specifies the maximum number of records to retrieve.
- Example: `limit: 100` retrieves only the first 100 records.

5. **`unit`**:
- Specifies the unit for the data values.
- Example: Use `BloodGlucoseUnit.MmolPerL` for `HealthLinkDataType.BloodGlucose`.
- Use the units that the library exports to avoid mismatch.

---

### **Examples Using `ReadOptions`**

#### Retrieve Blood Glucose Data Between Dates

```typescript
read(HealthLinkDataType.BloodGlucose, {
startDate: '2021-01-01T00:00:00Z',
endDate: '2021-12-31T23:59:59Z',
unit: BloodGlucoseUnit.MmolPerL,
});
```
4 changes: 4 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,7 @@ export const write = async <T extends WriteDataType>(
});
}
};

export * from './types/units';
export * from './types/dataTypes';
export * from './types/save';
13 changes: 13 additions & 0 deletions src/types/dataTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
import { type ReadRecordsOptions } from 'react-native-health-connect';

/**
* Enum representing various types of health data that can be tracked.
*
* @enum {string}
* @property {string} BloodGlucose - Represents blood glucose levels.
* @property {string} Height - Represents height measurement.
* @property {string} Weight - Represents weight measurement.
* @property {string} HeartRate - Represents heart rate measurement.
* @property {string} RestingHeartRate - Represents resting heart rate measurement.
* @property {string} BloodPressure - Represents blood pressure measurement.
* @property {string} OxygenSaturation - Represents oxygen saturation levels.
* @property {string} Steps - Represents the number of steps taken.
*/
export enum HealthLinkDataType {
BloodGlucose = 'BloodGlucose',
Height = 'Height',
Expand Down
10 changes: 10 additions & 0 deletions src/types/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ export type WriteOptions<T extends WriteDataType> = WriteOptionsBase<T> &
? { startDate: string; endDate: string }
: { startDate?: string; endDate?: string });

/**
* Represents the types of data that are supported in the write operation.
*
* @typedef {WriteDataType}
* @property {HealthLinkDataType.BloodGlucose} BloodGlucose - Represents blood glucose data.
* @property {HealthLinkDataType.Height} Height - Represents height data.
* @property {HealthLinkDataType.Weight} Weight - Represents weight data.
* @property {HealthLinkDataType.HeartRate} HeartRate - Represents heart rate data.
* @property {HealthLinkDataType.Steps} Steps - Represents steps data.
*/
export type WriteDataType =
| HealthLinkDataType.BloodGlucose
| HealthLinkDataType.Height
Expand Down

0 comments on commit bd0395b

Please sign in to comment.