Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .local/state/replit/agent/.latest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"latest": "main"}
{ "latest": "main" }
11 changes: 11 additions & 0 deletions ANALYSIS_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This document describes the Python-based data analysis and clinical decision sup
### 1. Load and Explore ✅

The script loads the diabetes dataset and provides comprehensive exploratory analysis:

- Dataset shape, columns, data types
- Summary statistics for all numeric features
- Missing value detection
Expand All @@ -22,6 +23,7 @@ The script loads the diabetes dataset and provides comprehensive exploratory ana
### 2. Data Cleaning & Preprocessing ✅

Implemented cleaning strategies:

- **Outlier handling**: Filters out unrealistic values based on medical thresholds
- **Categorical encoding**:
- Gender: Binary encoding (Male=1, Female=0)
Expand All @@ -32,13 +34,15 @@ Implemented cleaning strategies:
### 3. Model Building ✅

Logistic Regression model with:

- Balanced class weights to handle class imbalance
- Standardized features for proper coefficient interpretation
- Predicted probabilities (risk scores as percentages)

### 4. Interpretation & Outputs ✅

#### For Clinicians:

- **Risk Probability**: Exact percentage (e.g., "23.5%")
- **Top Contributing Factors**: 3-5 features with:
- Feature name
Expand All @@ -51,6 +55,7 @@ Logistic Regression model with:
- HIGH (>50%): Refer for diagnostic testing

#### For Patients:

- **Simplified Risk Category**: LOW/MODERATE/HIGH
- **Plain Language Factors**:
- "Your BMI is elevated"
Expand All @@ -64,13 +69,15 @@ Logistic Regression model with:
### 5. Visualizations ✅

The web interface provides:

- **Feature importance bar chart**: Displays coefficient magnitudes
- **Risk distribution histogram**: Shows separation between diabetic and non-diabetic cases
- **Individual factor contributions**: Diverging bar chart in clinician view

### 6. Workflow Documentation ✅

The code includes:

- Comprehensive comments explaining each step
- Markdown-style documentation in this file
- Clear function names and structure
Expand All @@ -92,6 +99,7 @@ python3 analyze.py
```

This will:

1. Generate synthetic data if `diabetes_dataset.csv` doesn't exist
2. Clean and preprocess the data
3. Train the logistic regression model
Expand All @@ -110,6 +118,7 @@ python3 analyze.py predict_file patient.json
```

Output:

```json
{
"riskScore": 96.9,
Expand Down Expand Up @@ -192,6 +201,7 @@ If no dataset is provided, the script generates 1000 synthetic patient records w
### Data Quality

The script handles:

- Missing values (filters them out)
- Unrealistic values:
- BMI < 10 (physiologically impossible)
Expand Down Expand Up @@ -221,6 +231,7 @@ The Python script integrates seamlessly with the Node.js backend:
## References

This implementation follows best practices from:

- Clinical prediction models for diabetes screening (ADA guidelines)
- Interpretable machine learning in healthcare
- Human-AI collaboration in clinical workflows
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
![Stars](https://img.shields.io/github/stars/gopaljilab/Clinical-Insight-Engine)
![Issues](https://img.shields.io/github/issues/gopaljilab/Clinical-Insight-Engine)
![Last Commit](https://img.shields.io/github/last-commit/gopaljilab/Clinical-Insight-Engine)
# 🩺 Clinical Insight Engine

# 🩺 Clinical Insight Engine

## Clinical Decision Support for Preventive Diabetes Risk Assessment

**Clinical Insight Engine** is a full-stack clinical decision support system designed to surface early diabetes risk signals from routine patient data.
Expand All @@ -20,7 +22,9 @@ This system is intended for **educational and research purposes only** and does
### 🔹 Core Functionality

#### 🧾 Risk Assessment Form

Inputs include:

- Age, gender
- Hypertension and heart disease status
- Smoking history
Expand All @@ -31,21 +35,25 @@ Inputs include:
#### 👥 Dual-View Results

**Clinician View**

- Exact risk percentage (0–100%)
- Top contributing factors with impact analysis
- Model confidence indicators
- Suggested follow-up actions

**Patient View**

- Simplified risk category (**LOW / MODERATE / HIGH**)
- Plain-language explanation of risk factors
- Preventive lifestyle recommendations

#### 🕒 Assessment History

- Stores previous assessments with timestamps
- Enables longitudinal tracking of patient risk

#### 📊 Data Visualization

- Interactive bar charts showing factor contributions
- Available in clinician view for transparency

Expand All @@ -54,6 +62,7 @@ Inputs include:
## 🏗️ System Architecture

### Frontend (`client/`)

- React + TypeScript
- Vite for fast development
- Tailwind CSS with dark mode support
Expand All @@ -63,12 +72,14 @@ Inputs include:
- Framer Motion for animations

### Backend (`server/`)

- Express.js REST API
- PostgreSQL database via Drizzle ORM
- Python integration for ML inference
- Zod-based route and schema validation

### Machine Learning (`analyze.py`)

- Logistic Regression (scikit-learn)
- Feature engineering and preprocessing
- StandardScaler for normalization
Expand All @@ -87,17 +98,20 @@ Inputs include:
## ⚙️ Installation & Setup

### 1️⃣ Clone the Repository

```bash
git clone https://github.com/gopaljilab/Clinical-Insight-Engine.git
cd Clinical-Insight-Engine
```

### 2️⃣ Install Node Dependencies

```bash
npm install
```

### 3️⃣ Create Environment File

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

```bash
Expand All @@ -109,13 +123,15 @@ Copy-Item .env.example .env
```

If `.env.example` doesn't exist, create `.env` manually:

```env
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/clinical_insight_engine
```

### 4️⃣ PostgreSQL Database Setup

#### Linux (Ubuntu/Debian)

```bash
# Install PostgreSQL
sudo apt update
Expand All @@ -131,6 +147,7 @@ sudo -u postgres psql -c "CREATE DATABASE clinical_insight_engine;"
```

#### macOS (Homebrew)

```bash
# Install PostgreSQL
brew install postgresql
Expand All @@ -144,6 +161,7 @@ psql postgres -c "CREATE DATABASE clinical_insight_engine;"
```

#### Windows

1. Download PostgreSQL from [postgresql.org](https://www.postgresql.org/download/windows/)
2. Install with default settings (remember the password for `postgres` user)
3. Open **SQL Shell (psql)** or **pgAdmin** and run:
Expand All @@ -154,18 +172,21 @@ CREATE DATABASE clinical_insight_engine;
```

Or via PowerShell (if `psql` is in PATH):

```powershell
psql -U postgres -d postgres -c "CREATE DATABASE clinical_insight_engine;"
```

### 5️⃣ Database Migration

Create the required tables:

```bash
npm run db:push
```

If the above doesn't work, try:

```bash
npm run migrate
# or
Expand All @@ -175,6 +196,7 @@ npm run db:migrate
### 6️⃣ Python Environment Setup

#### Linux/macOS

```bash
# Create virtual environment
python3 -m venv .venv
Expand All @@ -190,6 +212,7 @@ pip install -r requirements.txt
```

#### Windows (PowerShell)

```powershell
# Create virtual environment
py -m venv .venv
Expand All @@ -207,6 +230,7 @@ pip install -r requirements.txt
### 7️⃣ Dataset Preparation

If dataset exists in project:

```bash
# Linux/macOS
cp attached_assets/diabetes_dataset.csv ./diabetes_dataset.csv
Expand All @@ -216,6 +240,7 @@ Copy-Item attached_assets/diabetes_dataset.csv ./diabetes_dataset.csv
```

If dataset is missing, generate synthetic data:

```bash
# Linux/macOS
python3 -c "from analyze import create_synthetic_data; create_synthetic_data()"
Expand All @@ -227,12 +252,15 @@ py -c "from analyze import create_synthetic_data; create_synthetic_data()"
### 8️⃣ Start the Application

#### Frontend (React + Vite)

```bash
npm run dev
```

Frontend runs at: `http://localhost:5173`

#### ML Pipeline (Training)

```bash
# Linux/macOS
python3 analyze.py
Expand All @@ -242,6 +270,7 @@ py analyze.py
```

#### Backend API (if separate)

```bash
# Linux/macOS
python3 main.py
Expand All @@ -257,6 +286,7 @@ py main.py
Create a patient JSON file:

#### Linux/macOS

```bash
cat > patient.json << 'EOF'
{
Expand All @@ -273,6 +303,7 @@ EOF
```

#### Windows (PowerShell)

```powershell
@'
{
Expand All @@ -289,6 +320,7 @@ EOF
```

Run prediction:

```bash
# Linux/macOS
python3 analyze.py predict_file patient.json
Expand All @@ -302,9 +334,11 @@ py analyze.py predict_file patient.json
## 🛑 Shutdown

### 1️⃣ Stop Development Server

Press `Ctrl + C` in the terminal running `npm run dev`

### 2️⃣ Deactivate Python Environment

```bash
# Linux/macOS
deactivate
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
## 🏥 Preventive Risk & Clinical Decision Support

### Theme

Healthcare | Preventive Medicine | Human-AI Collaboration

### Context

Chronic diseases such as diabetes often develop silently. By the time symptoms appear, interventions become costly and outcomes worsen. Clinicians operate under time pressure, limited historical data, and uncertainty—while patients struggle to understand probabilistic health risks.

### Problem

Design a clinical decision support workflow that helps surface early risk signals from routine patient data and supports informed, timely interventions—without overwhelming doctors or misleading patients.

### What the Solution Should Enable
- Transform structured patient data into risk estimates with uncertainty
- Identify key contributing factors and modifiable drivers
- Communicate findings differently for clinicians and patients

- Transform structured patient data into risk estimates with uncertainty
- Identify key contributing factors and modifiable drivers
- Communicate findings differently for clinicians and patients
- Suggest next-step actions (tests, lifestyle changes, follow-ups)

### Open Design Space

Teams may explore:
- Risk scoring, stratification, or cohort discovery
- Counterfactual reasoning (“what would reduce risk most?”)
- Longitudinal patient tracking

- Risk scoring, stratification, or cohort discovery
- Counterfactual reasoning (“what would reduce risk most?”)
- Longitudinal patient tracking
- Bias detection and safety considerations

### Evaluation Focus
- Clinical relevance of insights
- Clarity and trustworthiness of explanations
- Usability in real OPD / clinic workflows

- Clinical relevance of insights
- Clarity and trustworthiness of explanations
- Usability in real OPD / clinic workflows
Loading