File size: 8,181 Bytes
ed0b977
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
---
title: Swift Query
emoji: πŸ“š
colorFrom: blue
colorTo: indigo
sdk: docker
pinned: false
license: apache-2.0
short_description: Privacy-Preserving Clinical Intelligence System
---

# SwiftQuery: Secure Medical AI with CyborgDB

**A Privacy-First Healthcare OS validating Encrypted Vector Search.**

---

> [!CAUTION]
> **OS REQUIREMENT: LINUX OR WSL (Windows Subsystem for Linux)**
> due to the **"CyborgDB Effect"**, this application **CANNOT** run on native Windows.
> The core `cyborgdb-core` encryption libraries currently require a Linux environment.
> Users on Windows **MUST** use WSL2 (Ubuntu 20.04+ recommended).

---

## Project Details

SwiftQuery is a secure, AI-powered healthcare operating system designed to demonstrate the power of encrypted vector search in a medical context. It provides a platform for managing patient data, interacting with AI assistants, and ensuring that sensitive patient information remains private and secure, even during complex AI-powered searches.

The backend is built with Python and Flask, leveraging MongoDB for data storage. The AI capabilities are powered by Google's Gemini models and the Langchain framework.

The core of SwiftQuery's security model is **CyborgDB**.

## Features

### Core Features

*   **Secure User Authentication:** Separate login and registration for doctors, patients, and assistants.
*   **Role-Based Dashboards:** Customized dashboards for each user type, providing access to relevant information and actions.
*   **AI-Powered Clinical Summarization:** Utilizes generative AI to create concise summaries of patient records.
*   **Intelligent Patient Search:** Enables searching for patients based on symptoms, diagnoses, or other clinical notes.

### Focus on CyborgDB: Encrypted Vector Search

CyborgDB is central to SwiftQuery's mission of providing a privacy-first healthcare platform. Here's how it's used:

*   **Encryption at the Core:** Instead of performing similarity searches on raw, unencrypted patient data, SwiftQuery uses CyborgDB to encrypt the vector embeddings of patient information. This means that sensitive data is never exposed in its raw form during AI-powered search operations.
*   **Secure Similarity Search:** When a doctor searches for patients with similar symptoms, the query is also encrypted and sent to CyborgDB. The similarity search is performed on the *encrypted* data, ensuring that the underlying patient information remains confidential.
*   **Privacy-Preserving AI:** By integrating CyborgDB, SwiftQuery can leverage the power of AI for tasks like patient similarity search without compromising patient privacy. The AI models interact with encrypted data, not the raw, sensitive information.
*   **"The CyborgDB Effect":** This project highlights the "CyborgDB Effect," where the use of advanced encryption technologies necessitates a specific development environment (Linux/WSL) to ensure the highest level of security. This is a deliberate design choice to prioritize security and privacy.

## πŸš€ Getting Started

### 1. Prerequisites
- **OS:** Linux (Ubuntu/Debian) or Windows + WSL2.
- **Python:** 3.9+
- **MongoDB:** A URI for a MongoDB Instance (Local or Atlas).
- **API Keys:**
    - `GOOGLE_AI_API_KEY`: For Gemini 1.5 Pro/Flash.
    - `CYBORGDB_API_KEY`: For Encrypted Vector Search.

### 2. Installation

1.  **Clone the Repository**
    ```bash
    git clone https://github.com/Darshanroy/SwiftQuery.git
    cd SwiftQuery
    ```

2.  **Set Up Virtual Environment**
    ```bash
    python3 -m venv .venv
    source .venv/bin/activate
    ```

3.  **Install Dependencies**
    *Note: This step will fail on native Windows due to CyborgDB dependencies.*
    ```bash
    pip install -r requirements.txt
    ```

### 3. Configuration

Create a `.env` file in the root directory:

```ini
# Core Secrets
SECRET_KEY=your_development_secret_key
MONGO_URI=mongodb+srv://<user>:<password>@cluster.mongodb.net/?retryWrites=true&w=majority

# AI & Encrypted Search
GOOGLE_AI_API_KEY=your_gemini_api_key
CYBORGDB_API_KEY=your_cyborgdb_api_key

# Optional: Port Configuration
PORT=8092
```

### 4. Running the Application

Use the provided helper script to start the server:

```bash
chmod +x devserver.sh
./devserver.sh
```

Or run manually with Python:

```bash
python3 main.py
```

Server will start at `http://localhost:8092`.

---

## File Structure

```
.
β”œβ”€β”€ GEMINI.md
β”œβ”€β”€ README.md
β”œβ”€β”€ ai_agents
β”‚   β”œβ”€β”€ clinical_summarizer.py
β”‚   β”œβ”€β”€ patient_rag.py
β”‚   └── rag_similar_patient.py
β”œβ”€β”€ app.log
β”œβ”€β”€ db.py
β”œβ”€β”€ devserver.sh
β”œβ”€β”€ documentation
β”‚   β”œβ”€β”€ backend_ai.md
β”‚   β”œβ”€β”€ backend_general.md
β”‚   └── vectordb_integration.md
β”œβ”€β”€ global_error.txt
β”œβ”€β”€ main.py
β”œβ”€β”€ patient.py
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ static
β”‚   └── script.js
β”œβ”€β”€ templates
β”‚   β”œβ”€β”€ admin
β”‚   β”œβ”€β”€ assistant
β”‚   β”œβ”€β”€ doctor
β”‚   β”œβ”€β”€ index.html
β”‚   └── patient
β”œβ”€β”€ tests
β”‚   β”œβ”€β”€ audit_assistants.py
β”‚   β”œβ”€β”€ check_env.py
β”‚   β”œβ”€β”€ create_chat_session_collection.py
β”‚   β”œβ”€β”€ debug_assistant_routes.py
β”‚   β”œβ”€β”€ debug_dashboard_error.py
β”‚   β”œβ”€β”€ debug_direct.py
β”‚   β”œβ”€β”€ debug_dns_python.py
β”‚   β”œβ”€β”€ debug_patient_search.py
β”‚   β”œβ”€β”€ debug_patients.py
β”‚   β”œβ”€β”€ debug_render.py
β”‚   β”œβ”€β”€ debug_simple.py
β”‚   β”œβ”€β”€ debug_uri.py
β”‚   β”œβ”€β”€ debug_uri_2.py
β”‚   β”œβ”€β”€ extract_data.py
β”‚   β”œβ”€β”€ init_db.py
β”‚   β”œβ”€β”€ inspect_db.py
β”‚   β”œβ”€β”€ inspect_patient.py
β”‚   β”œβ”€β”€ reset_db_schema.py
β”‚   β”œβ”€β”€ reset_password.py
β”‚   β”œβ”€β”€ test_google_dns.py
β”‚   β”œβ”€β”€ test_render_assistant.py
β”‚   β”œβ”€β”€ verify_fix.py
β”‚   β”œβ”€β”€ verify_history.py
β”‚   β”œβ”€β”€ verify_login.py
β”‚   β”œβ”€β”€ verify_recording.py
β”‚   β”œβ”€β”€ verify_search_mode.py
β”‚   β”œβ”€β”€ verify_view.py
β”‚   └── verify_workflow.py
└── utils
    β”œβ”€β”€ blueprints
    β”‚   β”œβ”€β”€ admin.py
    β”‚   β”œβ”€β”€ ai.py
    β”‚   β”œβ”€β”€ assistant.py
    β”‚   β”œβ”€β”€ auth.py
    β”‚   β”œβ”€β”€ chat.py
    β”‚   β”œβ”€β”€ doctor.py
    β”‚   β”œβ”€β”€ enhancer.py
    β”‚   β”œβ”€β”€ history.py
    β”‚   └── patient.py
    β”œβ”€β”€ db
    β”‚   β”œβ”€β”€ db.py
    β”‚   └── helper.py
    └── logging
        β”œβ”€β”€ logger.py
        └── logger_setup.py

```

## File Details

| File/Folder | Description |
|---|---|
| `main.py` | The main entry point for the Flask application. It initializes the app, registers blueprints, and starts the server. |
| `requirements.txt` | Lists all the Python dependencies for the project. |
| `.env` | Configuration file for storing secrets and environment variables like API keys and database URIs. |
| `devserver.sh` | A shell script for convenience to run the development server. |
| `ai_agents/` | Contains the core AI logic. This includes scripts for clinical summarization, patient RAG, and similar patient search using encrypted vector search. |
| `utils/blueprints/` | This directory contains the Flask Blueprints, which organize the application's routes into modular components (e.g., `auth.py`, `patient.py`, `doctor.py`). |
| `templates/` | Contains all the HTML templates for the web interface, organized by user roles (admin, assistant, doctor, patient). |
| `static/` | Holds static assets such as CSS, JavaScript (`script.js`), and images. |
| `tests/` | Contains all the testing, debugging, and utility scripts for the project. |
| `db.py` | Includes functions for interacting with the MongoDB database. |
| `patient.py` | Defines the `Patient` class and related functions for patient data management. |


## ⚠️ Known Limitations
-   **Windows Support:** Not available. Requires WSL or Linux VM.
-   **Memory Usage:** The local embedding model (`all-MiniLM-L6-v2`) requires ~500MB RAM.
-   **SRV Timeouts:** On some WSL configurations, DNS issues may occur. The app includes a patch to force Google DNS (`8.8.8.8`).

---
**Built for the CyborgDB Hackathon.**
*Demonstrating Encrypted Vector Search in Healthcare.*