vorqard-ai-sdk 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,209 +1,228 @@
1
- # VORQARD AI Health Assistant SDK
2
-
3
- [![GitHub](https://img.shields.io/badge/GitHub-AbhivornGroupIn%2FVORQARD__SDK__AI-blue?logo=github)](https://github.com/AbhivornGroupIn/VORQARD_SDK_AI)
4
-
5
- The VORQARD AI SDK is a standalone React Native / Expo module that provides a conversational AI clinical health assistant and a structured medical report analyzer.
6
-
7
- ---
8
-
9
- ## 🚀 Step-by-Step Integration Guide
10
-
11
- Follow these steps to integrate the AI SDK into your React Native / Expo application (such as the Groupin App):
12
-
13
- ### Step 1: Copy the SDK Folder
14
- Copy the `VORQARD_AI_SDK` directory into your project structure. A common setup is to place it side-by-side with your host application:
15
- ```text
16
- /my-workspace
17
- ├── groupin-app/ (Your main mobile application directory)
18
- └── VORQARD_AI_SDK/ (This SDK directory)
19
- ```
20
-
21
- ### Step 2: Install Peer Dependencies
22
- The SDK relies on standard Expo and React Native libraries for image picking, safe area views, icons, and network requests.
23
-
24
- Run the following command in your main application folder (`groupin-app/`):
25
- ```bash
26
- npx expo install axios expo-linear-gradient expo-image-picker expo-camera @expo/vector-icons react-native-safe-area-context
27
- ```
28
-
29
- ### Step 3: Link the SDK to Your App
30
- In your main application folder (`groupin-app/`), install the SDK package as a local file dependency by running:
31
- ```bash
32
- npm install ../VORQARD_AI_SDK
33
- ```
34
- *(This automatically adds `"vorqard-ai-sdk": "file:../VORQARD_AI_SDK"` to your dependencies in `package.json` and configures node module resolution)*.
35
-
36
- ### Step 4: Render the AI Assistant Screen
37
- Import `VorqardAIAssistant` and add it to any screen, layout, or modal in your navigation stack.
38
-
39
- Here is a basic template:
40
-
41
- ```javascript
42
- import React from 'react';
43
- import { SafeAreaView, StyleSheet } from 'react-native';
44
- import { VorqardAIAssistant } from 'vorqard-ai-sdk';
45
-
46
- export default function AIExpertScreen({ navigation }) {
47
- // Retrieve the patient's authenticated token and first name from your app's auth state
48
- const userToken = "eyJhbGciOi..."; // Active patient JWT session token
49
- const patientName = "Jagadish"; // Used for personalized greeting
50
-
51
- return (
52
- <SafeAreaView style={styles.container}>
53
- <VorqardAIAssistant
54
- backendUrl="https://app.vorqard.com/api" // VORQARD production API endpoint
55
- userToken={userToken} // Authentication JWT
56
- patientName={patientName} // Custom patient name
57
- onClose={() => navigation.goBack()} // Callback when close/back button is pressed
58
- aiLogo={require('./assets/AI_Icon.png')} // Optional: custom icon for AI replies
59
- />
60
- </SafeAreaView>
61
- );
62
- }
63
-
64
- const styles = StyleSheet.create({
65
- container: {
66
- flex: 1,
67
- },
68
- });
69
- ```
70
-
71
- ---
72
-
73
- ## 🛠 Advanced / Decoupled Usage
74
-
75
- If you want to render your own custom user interface and only use the state management and API integration layer of the SDK, you can import the initialization client and custom hooks directly:
76
-
77
- ```javascript
78
- import { initSDKClient, getSDKClient, useHealthChat } from 'vorqard-ai-sdk';
79
-
80
- // 1. Initialize the HTTP client configuration
81
- initSDKClient('https://app.vorqard.com/api', 'JWT_TOKEN_HERE');
82
-
83
- // 2. Consume the custom health chat state hook in your own component
84
- const MyCustomChat = () => {
85
- const { messages, sendMessage, loading } = useHealthChat('chat', 'Jagadish');
86
- // messages contains: [{ id, role, content, ui_action, timestamp }]
87
- // sendMessage is a function to send the next prompt
88
- };
89
- ```
90
-
91
- ---
92
-
93
- ## 🌐 Backend API Endpoints Reference
94
-
95
- The SDK automatically communicates with the following backend routes. Ensure your API gateway/server allows the client's JWT token authorization on these endpoints:
96
-
97
- ### 1. Patient Dashboard Context
98
- * **Path:** `GET /patients/dashboard/me`
99
- * **Headers:** `Authorization: Bearer <userToken>`
100
- * **Description:** Fetches core summary details of the logged-in patient (e.g. name, date of last visit) to personalize the greeting.
101
-
102
- ### 2. Patient Medical Records
103
- * **Path:** `GET /patients/records/me`
104
- * **Headers:** `Authorization: Bearer <userToken>`
105
- * **Description:** Fetches past clinical records and consult history to provide relevant diagnostic context to the AI model.
106
-
107
- ### 3. AI Health Chat Engine
108
- * **Path:** `POST /patients/ai/chat`
109
- * **Headers:** `Authorization: Bearer <userToken>`
110
- * **Request Body:**
111
- ```json
112
- {
113
- "message": "book appointment",
114
- "history": [
115
- { "role": "user", "content": "hello" },
116
- { "role": "assistant", "content": "Hi there! How can I help you today?" }
117
- ]
118
- }
119
- ```
120
- * **Response Body:**
121
- ```json
122
- {
123
- "response": "Here is a list of hospital-associated doctors...",
124
- "ui_action": {
125
- "type": "selection",
126
- "title": "Select Doctor",
127
- "options": [
128
- { "id": "129", "label": "Dr. Veeha Reddy", "name": "Dr. Veeha Reddy" }
129
- ]
130
- }
131
- }
132
- ```
133
- * **Description:** The chat router interface. It passes user utterances and conversational history to return clinical AI responses and rich-action metadata.
134
-
135
- ### 4. AI Report Analyzer (Optional)
136
- * **Path:** `POST /patients/ai/analyze-report`
137
- * **Headers:** `Authorization: Bearer <userToken>`
138
- * **Request Body:** `Multipart Form-Data` (keys: `file`)
139
- * **Description:** Submits physical medical report images for OCR scanning and structured health scoring.
140
-
141
- ---
142
-
143
- ## 🤝 Integration Path Options
144
-
145
- Groupin can choose one of two integration approaches based on their requirements:
146
-
147
- ---
148
-
149
- ### Option A: SDK Integration (Recommended — AI-powered)
150
- Use the SDK component described in this README. The AI chat handles hospital search, doctor discovery, slot picking, and appointment booking — all through a single conversational interface.
151
-
152
- **What Groupin needs to provide:**
153
- - `backendUrl` — VORQARD API base URL
154
- - `userToken` Patient JWT token (from OTP login)
155
-
156
- **Endpoints used internally by SDK (no manual calls needed):**
157
-
158
- | Endpoint | Method | Purpose |
159
- |---|---|---|
160
- | `/auth/send-otp-mobile` | POST | Send OTP to patient phone |
161
- | `/auth/verify-otp-mobile` | POST | Verify OTP → get JWT token |
162
- | `/patients/ai/chat` | POST | Full AI booking + health chat |
163
- | `/patients/ai/analyze-report` | POST | Medical report OCR analysis |
164
-
165
- ---
166
-
167
- ### Option B: Direct Partner API (Custom UI — no SDK required)
168
- If Groupin prefers to build their own UI and call VORQARD APIs directly from their backend server.
169
-
170
- **Authentication:** All requests must include the partner API key in the header:
171
- ```
172
- X-Api-Key: <provided_by_vorqard>
173
- ```
174
-
175
- **Backend URL:** `https://app.vorqard.com/api`
176
-
177
- **Available Partner Endpoints:**
178
-
179
- | Endpoint | Method | Purpose |
180
- |---|---|---|
181
- | `/partner/groupin/sync-user` | POST | Register/sync a Groupin user as a VORQARD patient |
182
- | `/partner/groupin/hospitals` | GET | Fetch all available hospitals |
183
- | `/partner/groupin/doctors` | GET | Fetch doctors (filter by specialty or hospital) |
184
- | `/partner/groupin/book-appointment` | POST | Book an appointment directly |
185
-
186
- **ExampleSync User Request Body:**
187
- ```json
188
- {
189
- "phone_number": "9876543210",
190
- "user_name": "Ravi Kumar",
191
- "email": "ravi@example.com",
192
- "gender": "Male",
193
- "date_of_birth": "1990-05-15",
194
- "blood_group": "O+",
195
- "location": "Hyderabad"
196
- }
197
- ```
198
-
199
- **Example — Book Appointment Request Body:**
200
- ```json
201
- {
202
- "vorqard_patient_id": 42,
203
- "vorqard_doctor_id": 7,
204
- "date": "2026-06-20",
205
- "time_slot": "10:00"
206
- }
207
- ```
208
-
209
-
1
+ # VORQARD AI Health Assistant SDK
2
+
3
+ [![GitHub](https://img.shields.io/badge/GitHub-AbhivornGroupIn%2FVORQARD__SDK__AI-blue?logo=github)](https://github.com/AbhivornGroupIn/VORQARD_SDK_AI)
4
+
5
+ The VORQARD AI SDK is a standalone React Native / Expo module that provides a conversational AI clinical health assistant and a structured medical report analyzer.
6
+
7
+ ---
8
+
9
+ ## 🚀 Step-by-Step Integration Guide
10
+
11
+ Follow these steps to integrate the AI SDK into your React Native / Expo application (such as the Groupin App):
12
+
13
+ ### Step 1: Copy the SDK Folder
14
+ Copy the `VORQARD_AI_SDK` directory into your project structure. A common setup is to place it side-by-side with your host application:
15
+ ```text
16
+ /my-workspace
17
+ ├── groupin-app/ (Your main mobile application directory)
18
+ └── VORQARD_AI_SDK/ (This SDK directory)
19
+ ```
20
+
21
+ ### Step 2: Install Peer Dependencies
22
+ The SDK relies on standard React Native libraries for image picking, safe area views, icons, and network requests.
23
+
24
+ Run the following command in your main application folder (`groupin-app/`):
25
+ ```bash
26
+ npm install axios react-native-linear-gradient react-native-image-crop-picker react-native-vision-camera react-native-vector-icons react-native-safe-area-context
27
+ ```
28
+
29
+ ### Step 3: Install the SDK
30
+ In your main application folder (`groupin-app/`), install the SDK package from npm by running:
31
+ ```bash
32
+ npm install vorqard-ai-sdk
33
+ ```
34
+
35
+ ### Step 4: Render the AI Assistant Screen
36
+ Import `VorqardAIAssistant` and add it to any screen, layout, or modal in your navigation stack.
37
+
38
+ Here is a basic template:
39
+
40
+ ```javascript
41
+ import React from 'react';
42
+ import { SafeAreaView, StyleSheet } from 'react-native';
43
+ import { VorqardAIAssistant } from 'vorqard-ai-sdk';
44
+
45
+ export default function AIExpertScreen({ navigation }) {
46
+ // Retrieve the patient's authenticated token and first name from your app's auth state
47
+ const userToken = "eyJhbGciOi..."; // Active patient JWT session token
48
+ const patientName = "Jagadish"; // Used for personalized greeting
49
+
50
+ return (
51
+ <SafeAreaView style={styles.container}>
52
+ <VorqardAIAssistant
53
+ backendUrl="https://app.vorqard.com/api" // VORQARD production API endpoint
54
+ userToken={userToken} // Authentication JWT
55
+ patientName={patientName} // Custom patient name
56
+ onClose={() => navigation.goBack()} // Callback when close/back button is pressed
57
+ aiLogo={require('./assets/AI_Icon.png')} // Optional: custom icon for AI replies
58
+ onTokenRefresh={async () => {
59
+ // Triggered automatically if the token expires (401 error)
60
+ const newToken = await fetchNewTokenFromYourBackend();
61
+ setVorqardToken(newToken);
62
+ return newToken; // The SDK will retry the failed request using this
63
+ }}
64
+ />
65
+ </SafeAreaView>
66
+ );
67
+ }
68
+
69
+ const styles = StyleSheet.create({
70
+ container: {
71
+ flex: 1,
72
+ },
73
+ });
74
+ ```
75
+
76
+ ---
77
+
78
+ ## 🛠 Advanced / Decoupled Usage
79
+
80
+ If you want to render your own custom user interface and only use the state management and API integration layer of the SDK, you can import the initialization client and custom hooks directly:
81
+
82
+ ```javascript
83
+ import { initSDKClient, getSDKClient, useHealthChat } from 'vorqard-ai-sdk';
84
+
85
+ // 1. Initialize the HTTP client configuration
86
+ initSDKClient('https://app.vorqard.com/api', 'JWT_TOKEN_HERE');
87
+
88
+ // 2. Consume the custom health chat state hook in your own component
89
+ const MyCustomChat = () => {
90
+ const { messages, sendMessage, loading } = useHealthChat('chat', 'Jagadish');
91
+ // messages contains: [{ id, role, content, ui_action, timestamp }]
92
+ // sendMessage is a function to send the next prompt
93
+ };
94
+ ```
95
+
96
+ ---
97
+
98
+ ## 🌐 Backend API Endpoints Reference
99
+
100
+ The SDK automatically communicates with the following backend routes. Ensure your API gateway/server allows the client's JWT token authorization on these endpoints:
101
+
102
+ ### 1. Patient Dashboard Context
103
+ * **Path:** `GET /patients/dashboard/me`
104
+ * **Headers:** `Authorization: Bearer <userToken>`
105
+ * **Description:** Fetches core summary details of the logged-in patient (e.g. name, date of last visit) to personalize the greeting.
106
+
107
+ ### 2. Patient Medical Records
108
+ * **Path:** `GET /patients/records/me`
109
+ * **Headers:** `Authorization: Bearer <userToken>`
110
+ * **Description:** Fetches past clinical records and consult history to provide relevant diagnostic context to the AI model.
111
+
112
+ ### 3. AI Health Chat Engine
113
+ * **Path:** `POST /patients/ai/chat`
114
+ * **Headers:** `Authorization: Bearer <userToken>`
115
+ * **Request Body:**
116
+ ```json
117
+ {
118
+ "message": "book appointment",
119
+ "history": [
120
+ { "role": "user", "content": "hello" },
121
+ { "role": "assistant", "content": "Hi there! How can I help you today?" }
122
+ ]
123
+ }
124
+ ```
125
+ * **Response Body:**
126
+ ```json
127
+ {
128
+ "response": "Here is a list of hospital-associated doctors...",
129
+ "ui_action": {
130
+ "type": "selection",
131
+ "title": "Select Doctor",
132
+ "options": [
133
+ { "id": "129", "label": "Dr. Veeha Reddy", "name": "Dr. Veeha Reddy" }
134
+ ]
135
+ }
136
+ }
137
+ ```
138
+ * **Description:** The chat router interface. It passes user utterances and conversational history to return clinical AI responses and rich-action metadata.
139
+
140
+ ### 4. AI Report Analyzer (Optional)
141
+ * **Path:** `POST /patients/ai/analyze-report`
142
+ * **Headers:** `Authorization: Bearer <userToken>`
143
+ * **Request Body:** `Multipart Form-Data` (keys: `file`)
144
+ * **Description:** Submits physical medical report images for OCR scanning and structured health scoring.
145
+
146
+ ---
147
+
148
+ ## 🤝 Integration Path Options
149
+
150
+ Groupin can choose one of two integration approaches based on their requirements:
151
+
152
+ ---
153
+
154
+ ### Option A: SDK Integration (Recommended AI-powered)
155
+ Use the SDK component described in this README. The AI chat handles hospital search, doctor discovery, slot picking, and appointment booking — all through a single conversational interface.
156
+
157
+ **What Groupin needs to Do:**
158
+ - `backendUrl` VORQARD API base URL (e.g., `https://app.vorqard.com/api`)
159
+ - `userToken` — Patient JWT token
160
+
161
+ > **Getting a Token for Testing & Production:**
162
+ > To retrieve a valid `userToken`, call the `/partner/groupin/sync-user` endpoint from your backend it now returns an `access_token` directly in the response. Pass this token straight to the SDK `userToken` prop. No separate OTP login step is needed.
163
+
164
+ **Endpoints used internally by SDK (no manual calls needed):**
165
+
166
+ | Endpoint | Method | Purpose |
167
+ |---|---|---|
168
+ | `/partner/groupin/sync-user` | POST | Register/sync user **→ returns `access_token` directly** |
169
+ | `/patients/ai/chat` | POST | Full AI booking + health chat |
170
+ | `/patients/ai/analyze-report` | POST | Medical report OCR analysis |
171
+
172
+ ### Props Reference
173
+
174
+ | Prop | Type | Required | Description |
175
+ |---|---|---|---|
176
+ | `backendUrl` | string | Yes | VORQARD API base URL |
177
+ | `userToken` | string | Yes | JWT token from `sync-user` |
178
+ | `patientName` | string | No | First name for greeting (Default: `"there"`) |
179
+ | `onClose` | function | No | Called when user presses the back button |
180
+ | `aiLogo` | image | No | Custom AI avatar icon |
181
+ | `onAnalyzeReportPress` | function | No | Custom handler to override the default report analyzer screen |
182
+ | `onTokenRefresh` | function | No | Callback triggered on 401 errors. Return a promise that resolves to a new JWT token to automatically retry failed requests. |
183
+
184
+ ---
185
+
186
+ ### Option B: Direct Partner API (Custom UI no SDK required)
187
+ If Groupin prefers to build their own UI and call VORQARD APIs directly from their backend server.
188
+
189
+ **Authentication:** All requests must include the partner API key in the header:
190
+ ```
191
+ X-Api-Key: <provided_by_vorqard>
192
+ ```
193
+
194
+ **Backend URL:** `https://app.vorqard.com/api`
195
+
196
+ **Available Partner Endpoints:**
197
+
198
+ | Endpoint | Method | Purpose |
199
+ |---|---|---|
200
+ | `/partner/groupin/sync-user` | POST | Register/sync a Groupin user as a VORQARD patient |
201
+ | `/partner/groupin/hospitals` | GET | Fetch all available hospitals |
202
+ | `/partner/groupin/doctors` | GET | Fetch doctors (filter by specialty or hospital) |
203
+ | `/partner/groupin/book-appointment` | POST | Book an appointment directly |
204
+
205
+ **Example — Sync User Request Body:**
206
+ ```json
207
+ {
208
+ "phone_number": "9876543210",
209
+ "user_name": "Ravi Kumar",
210
+ "email": "ravi@example.com",
211
+ "gender": "Male",
212
+ "date_of_birth": "1990-05-15",
213
+ "blood_group": "O+",
214
+ "location": "Hyderabad"
215
+ }
216
+ ```
217
+
218
+ **Example — Book Appointment Request Body:**
219
+ ```json
220
+ {
221
+ "vorqard_patient_id": 42,
222
+ "vorqard_doctor_id": 7,
223
+ "date": "2026-06-20",
224
+ "time_slot": "10:00"
225
+ }
226
+ ```
227
+
228
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vorqard-ai-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Standalone React Native SDK for VORQARD AI Health Assistant and Report Analyzer",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -12,14 +12,14 @@
12
12
  "url": "https://github.com/AbhivornGroupIn/VORQARD_SDK_AI/issues"
13
13
  },
14
14
  "peerDependencies": {
15
+ "axios": "^1.0.0",
15
16
  "react": ">=18.0.0",
16
17
  "react-native": ">=0.70.0",
17
- "axios": "^1.0.0",
18
- "react-native-linear-gradient": "*",
19
18
  "react-native-image-crop-picker": "*",
20
- "react-native-vision-camera": "*",
19
+ "react-native-linear-gradient": "*",
20
+ "react-native-safe-area-context": "*",
21
21
  "react-native-vector-icons": "*",
22
- "react-native-safe-area-context": "*"
22
+ "react-native-vision-camera": "*"
23
23
  },
24
24
  "keywords": [
25
25
  "vorqard",
@@ -29,6 +29,10 @@
29
29
  "healthcare"
30
30
  ],
31
31
  "author": "VORQARD Developer",
32
- "license": "Abhivorn Technologies"
32
+ "license": "Abhivorn Technologies",
33
+ "dependencies": {
34
+ "expo-av": "^16.0.8",
35
+ "expo-file-system": "~18.0.0",
36
+ "react-native-live-audio-stream": "^1.1.1"
37
+ }
33
38
  }
34
-
@@ -2,7 +2,7 @@ import axios from 'axios';
2
2
 
3
3
  let client = null;
4
4
 
5
- export const initSDKClient = (backendUrl, token) => {
5
+ export const initSDKClient = (backendUrl, token, onTokenRefresh = null) => {
6
6
  client = axios.create({
7
7
  baseURL: backendUrl,
8
8
  headers: {
@@ -10,6 +10,41 @@ export const initSDKClient = (backendUrl, token) => {
10
10
  ...(token ? { Authorization: `Bearer ${token}` } : {})
11
11
  }
12
12
  });
13
+
14
+ if (onTokenRefresh) {
15
+ client.interceptors.response.use(
16
+ (response) => response,
17
+ async (error) => {
18
+ const originalRequest = error.config;
19
+
20
+ // If it's a 401 error and we haven't already retried this exact request
21
+ if (error.response?.status === 401 && !originalRequest._retry) {
22
+ originalRequest._retry = true;
23
+
24
+ try {
25
+ // Ask the host app for a new token
26
+ const newToken = await onTokenRefresh();
27
+
28
+ if (newToken) {
29
+ // Update the default headers for future requests
30
+ client.defaults.headers.common['Authorization'] = `Bearer ${newToken}`;
31
+
32
+ // Update the headers of the failed request
33
+ originalRequest.headers['Authorization'] = `Bearer ${newToken}`;
34
+
35
+ // Retry the original request with the new token
36
+ return client(originalRequest);
37
+ }
38
+ } catch (refreshError) {
39
+ console.error('VORQARD AI SDK: Token refresh failed:', refreshError);
40
+ return Promise.reject(refreshError);
41
+ }
42
+ }
43
+
44
+ return Promise.reject(error);
45
+ }
46
+ );
47
+ }
13
48
  };
14
49
 
15
50
  export const getSDKClient = () => {
@@ -1,4 +1,6 @@
1
1
  export { DoctorTypeSelectionCard } from './cards/DoctorTypeSelectionCard';
2
+ export { SpecialtySelectionCard } from './cards/SpecialtySelectionCard';
3
+ export { RadiusSelectionCard } from './cards/RadiusSelectionCard';
2
4
  export { HospitalSelectionList, HospitalProfileCard } from './cards/HospitalCards';
3
5
  export { DoctorSelectionList, DoctorProfileCard } from './cards/DoctorCards';
4
6
  export { SlotSelectionCard } from './cards/SlotSelectionCard';