Files

5.4 KiB

DMH Role-Based Data Visualisation Platform

A high-security, role-governed healthcare data analytics platform for hospital admission records. Built for Deenanath Mangeshkar Hospital (DMH), supporting the 2025 inpatient dataset (admissionData-2025_v1.csv, 86,099 rows, 19 fields) and extensible to live enterprise databases.


The One Rule That Matters Most

The browser must never receive data the user is not allowed to see. All permission checks and all aggregations happen strictly on the backend. The frontend sends a declarative chart specification (JSON), never SQL. The backend validates it, applies user-specific column and row rules, executes an aggregated query via SQLAlchemy Core with bound parameters, and returns only the authorized result.


Stack

  • Backend: Python 3.11/3.13, FastAPI, SQLAlchemy 2.0 (Core for dynamic schema & query engine), Alembic migrations, Pydantic v2, PostgreSQL 16 (SQLite for zero-dependency dev/test), argon2-cffi for password hashing, PyJWT for tokens, pytest.
  • Frontend: React 18 + Vite + TypeScript, React Router 6, TanStack Query 5, Apache ECharts (echarts-for-react), Tailwind CSS, Lucide icons.
  • Deployment: Docker Compose (PostgreSQL 16, FastAPI backend, Nginx frontend).

Phase 1 — Foundation: Summary

  • Authentication & Security: Argon2 password hashing, signed JWT Bearer tokens with configurable TTL, role extraction.
  • Role-Based Access Control:
    • super_admin: Full control over data ingestion, users, schema attributes, and permissions.
    • viewer: Limited user, restricted to permitted data views.
    • department_manager: Department-scoped clinical head.
    • finance: Billing, payer mix, and TPA analyst.
  • User Management:
    • REST endpoints for Super Admin: GET /api/v1/users, POST /api/v1/users, GET /api/v1/users/{id}, PUT /api/v1/users/{id}, DELETE /api/v1/users/{id}.
    • Forbidden (HTTP 403) for non-super admins.
  • Dataset Ingestion Engine:
    • Full CSV ingestion pipeline (POST /api/v1/datasets/upload) supporting hospital records.
    • Automatic timestamp parsing for DD-MM-YYYY HH:MM (e.g. 01-01-2025 00:06).
    • Automatic column classification: sensitive fields (mrdNumber, AdmittingDoctorName) flagged as sensitive by default; bedNumber handled as text.
    • Batched insertion (5,000 rows per transaction) using SQLAlchemy Core table inserts.
    • Ingestion of 86,099 rows and 19 columns takes only seconds.
  • Admin & Viewer UI:
    • Modern, responsive React 18 + Vite + Tailwind interface.
    • Quick-switch demo accounts on Login screen.
    • User Management screen: create users, assign roles, toggle active status.
    • Dataset & Schema Inspector: upload CSV datasets, inspect fields, toggle column sensitivity.

Phase 2 & 3 — Access Control & Data Visualisation

  • Access Control Matrix:
    • Super admin configures dataset grants, column masking (hiding sensitive fields like mrdNumber and doctor identifiers), and row-level rules (e.g. AdmittingDoctorSpecialityName = 'MEDICINE' or PatientCategoryName = 'TPA').
    • Rule intersection: a user always sees the strict intersection of all permissions and row filters applying to them and their roles.
  • SQLAlchemy Core Query Engine:
    • The client transmits declarative JSON chart specifications (ChartSpec), never SQL.
    • Backend verifies permissions and whitelists every column against the dataset metadata before building parameterized SQLAlchemy Core expressions.
    • Zero raw patient records sent to browser — all aggregations (count, sum, avg, min, max, time-bucketing) happen on the backend.
  • Interactive Visualisations (Apache ECharts):
    • 4 KPI cards: Total Admissions, Average Patient Age, Active Departments, Hospital Wings.
    • Admissions by Medical Speciality (Top departments ranked).
    • Admissions by Hospital Building (Donut chart).
    • Monthly Inpatient Admission Trend (Smooth Area chart across 2025).
    • Admission Categories (Emergency vs Walk-in distribution).
    • Patient Payer Mix & Demographics (Stacked bar chart by Gender and Category).
  • Interactive Filters: Dynamic dropdown filters for Building, Speciality, and Admission Type, dynamically populated based on what the user's role allows.
  • Super Admin Simulation Tool ("Preview As"):
    • Super Admin can simulate any role (viewer, dept_manager, finance) with a single click in the top bar to inspect exactly how row rules and column masking are applied.

Quick Start & Running Locally

1. Backend Setup

cd backend
python -m venv .venv
# Windows:
.venv\Scripts\activate
# Linux/macOS:
source .venv/bin/activate

pip install -r requirements.txt
cp .env.example .env

# Initialize DB & Seed 86,099 admission records
python scripts/seed.py

# Start FastAPI server
uvicorn app.main:app --reload --port 8000

API Documentation will be live at: http://localhost:8000/docs

2. Frontend Setup

cd frontend
npm install
npm run dev

Open http://localhost:5173 in your browser.

3. Demo Credentials

Role Username Password
Super Admin admin Admin@123456
Staff Viewer viewer Viewer@123456
Dept Manager dept_manager Manager@123456
Finance User finance_user Finance@123456

Running Automated Tests

cd backend
python -m pytest

All 15 tests verify authentication, JWT security, argon2 hashing, 401/403 RBAC boundaries, CSV upload, column metadata updates, and row counts.