### Start Server Manually Source: https://github.com/shuchirj/hcgateway/blob/main/README.md Starts the Python server. Ensure environment variables are configured in `.env` and Firebase service account key is present. ```bash python3 main.py ``` -------------------------------- ### Start Mobile Application Source: https://github.com/shuchirj/hcgateway/blob/main/README.md Builds and starts the Android application. Ensure all prerequisites and patches are applied. ```bash npm run android ``` -------------------------------- ### Install Server Dependencies Source: https://github.com/shuchirj/hcgateway/blob/main/README.md Installs Python dependencies for the server. Ensure Python 3 and MongoDB are installed. ```bash pip install -r requirements.txt ``` -------------------------------- ### Clone and Navigate to API Directory Source: https://context7.com/shuchirj/hcgateway/llms.txt Clone the HCGateway repository and navigate to the API directory to begin server setup. ```bash git clone https://github.com/shuchir/hcgateway.git cd hcgateway/api ``` -------------------------------- ### Install Mobile App Dependencies Source: https://github.com/shuchirj/hcgateway/blob/main/README.md Installs Node.js dependencies for the mobile application. Ensure Node.js 18+ and npm are installed. ```bash npm install ``` -------------------------------- ### Configure Environment Variables Source: https://context7.com/shuchirj/hcgateway/llms.txt Copy the example environment file and edit it to configure the HCGateway API server settings, including host, port, debug mode, and database URI. ```bash cp .env.example .env # Edit .env: # APP_HOST=0.0.0.0 # APP_PORT=6644 # APP_DEBUG=True # MONGO_URI=mongodb://localhost:27017/hcgateway # FCM_PROJECT_ID=your-firebase-project-id ``` -------------------------------- ### Run Docker Containers Source: https://github.com/shuchirj/hcgateway/blob/main/README.md Use this command to start the API services using Docker Compose. Ensure environment variables are configured in `.env`. ```bash docker-compose up -d ``` -------------------------------- ### Database Migration Script Command Source: https://github.com/shuchirj/hcgateway/blob/main/README.md Command to run the database migration script. Requires 'appwrite' and 'pymongo' libraries to be installed. ```bash python3 migrate_1.5.0.py ``` -------------------------------- ### Decrypted Data Field Examples Source: https://context7.com/shuchirj/hcgateway/llms.txt Provides examples of decrypted data for various health record types, such as steps, heart rate, weight, and blood pressure. ```javascript // Decrypted data field examples: // Steps: {"count": 5432} // Heart Rate: {"samples": [{"beatsPerMinute": 72, "time": "..."}]} // Weight: {"weight": {"value": 75.5, "unit": "kilogram"}} // Blood Pressure: {"systolic": {...}, "diastolic": {...}, "bodyPosition": 1} ``` -------------------------------- ### Deploy HCGateway with Docker Source: https://context7.com/shuchirj/hcgateway/llms.txt Commands to clone, configure, and launch the HCGateway stack using Docker Compose. ```bash git clone https://github.com/shuchir/hcgateway.git cd hcgateway cp api/.env.example api/.env docker-compose up -d curl http://localhost:6644/api/v2/login \ -H "Content-Type: application/json" \ -d '{"username": "test", "password": "test"}' ``` -------------------------------- ### Navigate to App Directory Source: https://context7.com/shuchirj/hcgateway/llms.txt Navigate to the HCGateway application directory to begin the mobile app build process. ```bash cd hcgateway/app ``` -------------------------------- ### Build Release APK Source: https://github.com/shuchirj/hcgateway/blob/main/README.md Builds a release APK file for the Android application. This command is run from the `android/` directory. ```bash cd android && ./gradlew assembleRelease ``` -------------------------------- ### Login User and Obtain Access Token Source: https://context7.com/shuchirj/hcgateway/llms.txt Authenticates a user with username and password, returning a bearer token. A new account is created if the user does not exist. An optional FCM token can be provided for push notifications. ```bash # Login and receive authentication tokens curl -X POST https://api.hcgateway.shuchir.dev/api/v2/login \ -H "Content-Type: application/json" \ -d '{ "username": "myuser", "password": "mypassword", "fcmToken": "optional-firebase-token" }' # Response: # { # "token": "abc123xyz...", # "refresh": "refresh_token_here...", # "expiry": "2024-01-15T12:00:00.000000" # } ``` -------------------------------- ### Apply Patch for Foreground Service Source: https://github.com/shuchirj/hcgateway/blob/main/README.md Applies a patch to the foreground service library used in the mobile application. This command must be run before building the APK. ```bash npx patch-package ``` -------------------------------- ### Push Health Data Records Source: https://context7.com/shuchirj/hcgateway/llms.txt Use these endpoints to upload health metrics like heart rate or blood pressure to the gateway. ```bash curl -X PUT https://api.hcgateway.shuchir.dev/api/v2/push/heartRate \ -H "Authorization: Bearer your_access_token" \ -H "Content-Type: application/json" \ -d '{ "data": [ { "samples": [{"beatsPerMinute": 72, "time": "2024-01-15T08:00:00.000Z"}], "startTime": "2024-01-15T08:00:00.000Z", "endTime": "2024-01-15T08:01:00.000Z" }, { "samples": [{"beatsPerMinute": 85, "time": "2024-01-15T09:00:00.000Z"}], "startTime": "2024-01-15T09:00:00.000Z", "endTime": "2024-01-15T09:01:00.000Z" } ] }' ``` ```bash curl -X PUT https://api.hcgateway.shuchir.dev/api/v2/push/bloodPressure \ -H "Authorization: Bearer your_access_token" \ -H "Content-Type: application/json" \ -d '{ "data": { "systolic": {"value": 120, "unit": "millimetersOfMercury"}, "diastolic": {"value": 80, "unit": "millimetersOfMercury"}, "time": "2024-01-15T10:00:00.000Z" } }' ``` -------------------------------- ### User Authentication API Source: https://context7.com/shuchirj/hcgateway/llms.txt Endpoints for authenticating users, obtaining access tokens, and managing token validity. ```APIDOC ## POST /api/v2/login ### Description Authenticates a user with username and password, returning a bearer token valid for 12 hours. If the user doesn't exist, a new account is automatically created. The optional FCM token enables push notifications for remote data operations. ### Method POST ### Endpoint https://api.hcgateway.shuchir.dev/api/v2/login ### Parameters #### Request Body - **username** (string) - Required - The user's username. - **password** (string) - Required - The user's password. - **fcmToken** (string) - Optional - Firebase Cloud Messaging token for push notifications. ### Request Example ```json { "username": "myuser", "password": "mypassword", "fcmToken": "optional-firebase-token" } ``` ### Response #### Success Response (200) - **token** (string) - The access token. - **refresh** (string) - The refresh token. - **expiry** (string) - The expiration time of the access token. #### Response Example ```json { "token": "abc123xyz...", "refresh": "refresh_token_here...", "expiry": "2024-01-15T12:00:00.000000" } ``` ## POST /api/v2/refresh ### Description Obtains a new access token using a refresh token without requiring the user to re-authenticate with credentials. The refresh token remains valid after use. ### Method POST ### Endpoint https://api.hcgateway.shuchir.dev/api/v2/refresh ### Parameters #### Request Body - **refresh** (string) - Required - The refresh token. ### Request Example ```json { "refresh": "your_refresh_token_here" } ``` ### Response #### Success Response (200) - **token** (string) - The new access token. - **refresh** (string) - The refresh token (remains the same). - **expiry** (string) - The expiration time of the new access token. #### Response Example ```json { "token": "new_access_token...", "refresh": "same_refresh_token...", "expiry": "2024-01-15T24:00:00.000000" } ``` ## DELETE /api/v2/revoke ### Description Immediately invalidates all access and refresh tokens for the authenticated user, requiring a new login to access the API. ### Method DELETE ### Endpoint https://api.hcgateway.shuchir.dev/api/v2/revoke ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication. ### Response #### Success Response (200) - **success** (boolean) - Indicates if the revocation was successful. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Refresh Access Token Source: https://context7.com/shuchirj/hcgateway/llms.txt Obtains a new access token using a refresh token. The refresh token remains valid after use. This avoids the need for the user to re-authenticate with credentials. ```bash # Refresh an expired token curl -X POST https://api.hcgateway.shuchir.dev/api/v2/refresh \ -H "Content-Type: application/json" \ -d '{ "refresh": "your_refresh_token_here" }' # Response: # { # "token": "new_access_token...", # "refresh": "same_refresh_token...", # "expiry": "2024-01-15T24:00:00.000000" # } ``` -------------------------------- ### Users Database Structure Source: https://github.com/shuchirj/hcgateway/blob/main/README.md Defines the structure of the 'users' collection in the database. Passwords are encrypted using Argon 2. ```json users { _id: string username: string password: string fcmToken: string expiry: datetime token: string refresh: string } ``` -------------------------------- ### Fetch Health Data Records Source: https://context7.com/shuchirj/hcgateway/llms.txt Retrieve stored health data by specifying the data type in the URL path. ```bash curl -X POST https://api.hcgateway.shuchir.dev/api/v2/fetch/activeCaloriesBurned \ -H "Authorization: Bearer your_access_token" \ -H "Content-Type: application/json" \ -d '{}' ``` ```bash curl -X POST https://api.hcgateway.shuchir.dev/api/v2/fetch/exerciseSession \ -H "Authorization: Bearer your_access_token" \ -H "Content-Type: application/json" \ -d '{ "queries": { "start": {"$gte": "2024-01-01T00:00:00.000Z"} } }' ``` -------------------------------- ### Customize API Endpoint Source: https://context7.com/shuchirj/hcgateway/llms.txt Modify the API endpoint in App.js to point to your self-hosted HCGateway server. ```javascript // Default: let apiBase = 'https://api.hcgateway.shuchir.dev'; // Change to your self-hosted server URL ``` -------------------------------- ### POST /api/v2/fetch/{type} Source: https://context7.com/shuchirj/hcgateway/llms.txt Fetches health data records for a specific health data type. ```APIDOC ## POST /api/v2/fetch/{type} ### Description Retrieves health data records from the gateway for a specific health data type. ### Method POST ### Endpoint https://api.hcgateway.shuchir.dev/api/v2/fetch/{type} ### Parameters #### Path Parameters - **type** (string) - Required - The health data type. #### Request Body - **queries** (object) - Optional - Query filters for the data retrieval. ``` -------------------------------- ### Database Field Parameters Source: https://github.com/shuchirj/hcgateway/blob/main/README.md Explanation of parameters within the HCGateway database structure, including data encryption and backward compatibility notes for the 'id' field. ```plaintext - $id - The ID of the object. - data - The data of the object encrypted using Fernet. When asked for through the API, the data will be decrypted for you using the user's hashed password found from the user id. - id - The ID of the object- This is the same as `_id` and is only kept for backward compatibility. May be removed in future versions. - start - The start date and time of the object - end - The end date and time of the object. Might not be present for some objects. - app - The app package string that the object was synced from. ``` -------------------------------- ### Health Record Structure Source: https://context7.com/shuchirj/hcgateway/llms.txt Illustrates the structure of a health record document stored in user-specific MongoDB collections, including encrypted data and timestamps. ```javascript // Health record structure (hcgateway_[user_id].[dataType] collection) // Example: hcgateway_abc123.heartRate { "_id": "record-uuid-from-health-connect", "id": "record-uuid-from-health-connect", // Legacy field "data": "gAAAAABk...". // Fernet encrypted JSON data "app": "com.google.android.apps.fitness", "start": "2024-01-15T08:00:00.000Z", "end": "2024-01-15T08:05:00.000Z" // Optional for point-in-time records } ``` -------------------------------- ### User Document Structure Source: https://context7.com/shuchirj/hcgateway/llms.txt Defines the structure of a user document in the 'hcgateway.users' MongoDB collection, including authentication and token details. ```javascript // User document structure (hcgateway.users collection) { "_id": "user-unique-id", "username": "johndoe", "password": "$argon2id$...". // Argon2 hashed password "fcmToken": "firebase-device-token", "token": "current-access-token", "refresh": "current-refresh-token", "expiry": ISODate("2024-01-15T12:00:00.000Z") } ``` -------------------------------- ### PUT /api/v2/push/{type} Source: https://context7.com/shuchirj/hcgateway/llms.txt Pushes health data records to the gateway for a specific health data type. ```APIDOC ## PUT /api/v2/push/{type} ### Description Push health data records to the device. The {type} parameter specifies the health metric (e.g., heartRate, bloodPressure). ### Method PUT ### Endpoint https://api.hcgateway.shuchir.dev/api/v2/push/{type} ### Parameters #### Path Parameters - **type** (string) - Required - The health data type (e.g., heartRate, bloodPressure) #### Request Body - **data** (object/array) - Required - The health record data to be pushed. ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **message** (string) - Confirmation message. ``` -------------------------------- ### Push Health Data to Device Source: https://context7.com/shuchirj/hcgateway/llms.txt Sends a push notification to the user's device to insert new health records into the local Health Connect store. Records appear in the database after the next sync. Requires the HCGateway app running with a valid FCM token. ```bash # Push a single weight record curl -X PUT https://api.hcgateway.shuchir.dev/api/v2/push/weight \ -H "Authorization: Bearer your_access_token" \ -H "Content-Type: application/json" \ -d '{ "data": { "weight": {"value": 75.5, "unit": "kilogram"}, "time": "2024-01-15T07:30:00.000Z" } }' ``` -------------------------------- ### Revoke All User Tokens Source: https://context7.com/shuchirj/hcgateway/llms.txt Immediately invalidates all access and refresh tokens for the authenticated user. A new login is required to access the API after revocation. ```bash # Revoke all tokens for the current user curl -X DELETE https://api.hcgateway.shuchir.dev/api/v2/revoke \ -H "Authorization: Bearer your_access_token" # Response: # { # "success": true # } ``` -------------------------------- ### Data Operations API Source: https://context7.com/shuchirj/hcgateway/llms.txt Endpoints for fetching and pushing health data to and from the Health Connect store. ```APIDOC ## POST /api/v2/fetch/{dataType} ### Description Retrieves health records of a specific type from the database. Supports MongoDB query syntax for filtering results by date range, app source, or custom criteria. Data is automatically decrypted before being returned. ### Method POST ### Endpoint https://api.hcgateway.shuchir.dev/api/v2/fetch/{dataType} * **dataType** (string) - Required - The type of health data to fetch (e.g., heartRate, steps, sleepSession). ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication. #### Request Body - **queries** (object) - Optional - MongoDB query syntax for filtering results. - **field** (any) - Description of the query field (e.g., date range, app source). ### Request Example ```bash # Fetch all heart rate records curl -X POST https://api.hcgateway.shuchir.dev/api/v2/fetch/heartRate \ -H "Authorization: Bearer your_access_token" \ -H "Content-Type: application/json" \ -d '{}' # Fetch steps within a date range using MongoDB queries curl -X POST https://api.hcgateway.shuchir.dev/api/v2/fetch/steps \ -H "Authorization: Bearer your_access_token" \ -H "Content-Type: application/json" \ -d '{ "queries": { "start": { "$gte": "2024-01-01T00:00:00.000Z" }, "end": { "$lte": "2024-01-31T23:59:59.000Z" } } }' # Fetch sleep sessions from a specific app curl -X POST https://api.hcgateway.shuchir.dev/api/v2/fetch/sleepSession \ -H "Authorization: Bearer your_access_token" \ -H "Content-Type: application/json" \ -d '{ "queries": { "app": "com.samsung.shealth" } }' ``` ### Response #### Success Response (200) - **Array of health records** (object) - Each object represents a health record with fields like `_id`, `data`, `id`, `start`, `end`, `app`. #### Response Example ```json [ { "_id": "record-uuid-123", "data": {"count": 5432}, "id": "record-uuid-123", "start": "2024-01-15T08:00:00.000Z", "end": "2024-01-15T09:00:00.000Z", "app": "com.google.android.apps.fitness" } ] ``` ## PUT /api/v2/push/{dataType} ### Description Sends a push notification to the user's device instructing it to insert new health records into the local Health Connect store. The device must have the HCGateway app running with a valid FCM token. Records will appear in the database after the next sync. ### Method PUT ### Endpoint https://api.hcgateway.shuchir.dev/api/v2/push/{dataType} * **dataType** (string) - Required - The type of health data to push (e.g., weight). ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication. #### Request Body - **data** (object) - Required - The health data to be pushed. - **weight** (object) - Required for `weight` dataType. Contains `value` and `unit`. - **value** (number) - The weight value. - **unit** (string) - The unit of weight (e.g., "kilogram"). - **time** (string) - Required - The timestamp for the health record. ### Request Example ```json { "data": { "weight": {"value": 75.5, "unit": "kilogram"}, "time": "2024-01-15T07:30:00.000Z" } } ``` ``` -------------------------------- ### Fetch Health Data by Type Source: https://context7.com/shuchirj/hcgateway/llms.txt Retrieves health records of a specific type. Supports MongoDB query syntax for filtering by date range, app source, or custom criteria. Data is automatically decrypted before return. ```bash # Fetch all heart rate records curl -X POST https://api.hcgateway.shuchir.dev/api/v2/fetch/heartRate \ -H "Authorization: Bearer your_access_token" \ -H "Content-Type: application/json" \ -d '{}' # Fetch steps within a date range using MongoDB queries curl -X POST https://api.hcgateway.shuchir.dev/api/v2/fetch/steps \ -H "Authorization: Bearer your_access_token" \ -H "Content-Type: application/json" \ -d '{ "queries": { "start": {"$gte": "2024-01-01T00:00:00.000Z"}, "end": {"$lte": "2024-01-31T23:59:59.000Z"} } }' # Response: # [ # { # "_id": "record-uuid-123", # "data": {"count": 5432}, # "id": "record-uuid-123", # "start": "2024-01-15T08:00:00.000Z", # "end": "2024-01-15T09:00:00.000Z", # "app": "com.google.android.apps.fitness" # } # ] # Fetch sleep sessions from a specific app curl -X POST https://api.hcgateway.shuchir.dev/api/v2/fetch/sleepSession \ -H "Authorization: Bearer your_access_token" \ -H "Content-Type: application/json" \ -d '{ "queries": { "app": "com.samsung.shealth" } }' ``` -------------------------------- ### HCGateway Database Structure Source: https://github.com/shuchirj/hcgateway/blob/main/README.md Defines the structure for storing Health Connect data, keyed by user ID. Data is encrypted using Fernet. ```json hcgateway_[user_id]: string { dataType: string { _id: string data: string id: string start: datetime end: datetime app: string } } ``` -------------------------------- ### Remove Sentry from Mobile App Source: https://github.com/shuchirj/hcgateway/blob/main/README.md Commands to remove Sentry and its wizard from the React Native mobile application. This is an optional step if Sentry is not desired. ```bash yarn remove @sentry/react-native npx @sentry/wizard -i reactNative -p android --uninstall ``` -------------------------------- ### Delete Health Data Records Source: https://context7.com/shuchirj/hcgateway/llms.txt Remove specific health records from the device by providing their UUIDs. ```bash curl -X DELETE https://api.hcgateway.shuchir.dev/api/v2/delete/steps \ -H "Authorization: Bearer your_access_token" \ -H "Content-Type: application/json" \ -d '{ "uuid": "record-uuid-to-delete" }' ``` ```bash curl -X DELETE https://api.hcgateway.shuchir.dev/api/v2/delete/heartRate \ -H "Authorization: Bearer your_access_token" \ -H "Content-Type: application/json" \ -d '{ "uuid": [ "uuid-1", "uuid-2", "uuid-3" ] }' ``` -------------------------------- ### DELETE /api/v2/delete/{type} Source: https://context7.com/shuchirj/hcgateway/llms.txt Removes specific health records from the device by their UUID. ```APIDOC ## DELETE /api/v2/delete/{type} ### Description Sends a deletion request to the user's device to remove specific health records by UUID. ### Method DELETE ### Endpoint https://api.hcgateway.shuchir.dev/api/v2/delete/{type} ### Parameters #### Path Parameters - **type** (string) - Required - The health data type. #### Request Body - **uuid** (string/array) - Required - The UUID or list of UUIDs of the records to delete. ### Response #### Success Response (200) - **success** (boolean) - Indicates if the request was successful. - **message** (string) - Confirmation message. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.