Skip to content

vickycodesss/ehr-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

EHR System - Electronic Health Records Management

A production-ready Electronic Health Record (EHR) web application with comprehensive patient management, clinical workflows, lab integration, pharmacy, and care coordination features.

πŸ₯ System Overview

This EHR system is designed following real-world hospital workflows with role-based access control, comprehensive audit logging, and HIPAA-style security best practices.

Key Features

βœ… Patient Management - Complete patient demographics, medical history, diagnoses, medications, and allergies
βœ… Clinical Documentation - SOAP format clinical notes and treatment plans
βœ… Lab Integration - Lab order management and result uploads
βœ… Pharmacy - Electronic prescriptions and medication dispensing
βœ… Care Coordination - Referrals and external data sharing
βœ… Role-Based Access - 5 user roles with specific permissions
βœ… Audit Logging - Comprehensive tracking of all data access
βœ… Security - JWT authentication, bcrypt password hashing, SQL injection protection

πŸ› οΈ Technology Stack

Backend

  • Runtime: Node.js v18+
  • Framework: Express.js
  • Database: MySQL 8.0+
  • Authentication: JWT (JSON Web Tokens)
  • Password Hashing: bcrypt
  • Security: Helmet, CORS

Frontend

  • Framework: React 18
  • Build Tool: Vite
  • Styling: Tailwind CSS
  • Routing: React Router v6
  • HTTP Client: Axios
  • Icons: Lucide React
  • Date Handling: date-fns

πŸ“‹ Prerequisites

Before running this application, ensure you have:

  • Node.js (v18 or higher)
  • MySQL (v8.0 or higher)
  • npm or yarn package manager

πŸš€ Installation & Setup

1. Clone the Repository

cd ehr-system

2. Database Setup

# Login to MySQL
mysql -u root -p

# Create database and import schema
mysql -u root -p < database/schema.sql

# Import sample data (optional)
mysql -u root -p ehr_system < database/seed.sql

3. Backend Setup

cd backend

# Install dependencies
npm install

# Create environment file
copy .env.example .env

# Edit .env file with your MySQL credentials
# DB_HOST=localhost
# DB_USER=root
# DB_PASSWORD=your_password
# DB_NAME=ehr_system
# JWT_SECRET=your_secret_key_here

# Start the backend server
npm start

The backend API will run on http://localhost:5000

4. Frontend Setup

cd frontend

# Install dependencies
npm install

# Start the development server
npm run dev

The frontend application will run on http://localhost:5173

πŸ‘₯ Default User Credentials

The system comes with pre-configured users for testing:

Role Username Password Description
Admin admin password123 System administration
Doctor dr.smith password123 Primary care physician
Doctor dr.jones password123 Specialist
Nurse nurse.wilson password123 Registered nurse
Lab Technician lab.tech password123 Laboratory technician
Pharmacist pharmacist password123 Licensed pharmacist

⚠️ IMPORTANT: Change these passwords in production!

πŸ“ Project Structure

ehr-system/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── database.js          # MySQL connection pool
β”‚   β”œβ”€β”€ controllers/
β”‚   β”‚   β”œβ”€β”€ authController.js    # Authentication logic
β”‚   β”‚   β”œβ”€β”€ patientController.js # Patient management
β”‚   β”‚   β”œβ”€β”€ clinicalController.js# Clinical notes & vitals
β”‚   β”‚   β”œβ”€β”€ labController.js     # Lab orders & results
β”‚   β”‚   β”œβ”€β”€ pharmacyController.js# Prescriptions
β”‚   β”‚   β”œβ”€β”€ careController.js    # Referrals & sharing
β”‚   β”‚   └── adminController.js   # User & audit management
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”œβ”€β”€ auth.js              # JWT & RBAC middleware
β”‚   β”‚   └── audit.js             # Audit logging
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ auth.routes.js
β”‚   β”‚   β”œβ”€β”€ patient.routes.js
β”‚   β”‚   β”œβ”€β”€ clinical.routes.js
β”‚   β”‚   β”œβ”€β”€ lab.routes.js
β”‚   β”‚   β”œβ”€β”€ pharmacy.routes.js
β”‚   β”‚   β”œβ”€β”€ care.routes.js
β”‚   β”‚   └── admin.routes.js
β”‚   β”œβ”€β”€ server.js                # Express app entry point
β”‚   β”œβ”€β”€ package.json
β”‚   └── .env.example
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ Auth/
β”‚   β”‚   β”‚   β”‚   └── Login.jsx
β”‚   β”‚   β”‚   └── Layout/
β”‚   β”‚   β”‚       └── Sidebar.jsx
β”‚   β”‚   β”œβ”€β”€ context/
β”‚   β”‚   β”‚   └── AuthContext.jsx
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   β”œβ”€β”€ Doctor/
β”‚   β”‚   β”‚   β”‚   └── DoctorDashboard.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Nurse/
β”‚   β”‚   β”‚   β”‚   └── NurseDashboard.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Lab/
β”‚   β”‚   β”‚   β”‚   └── LabDashboard.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Pharmacy/
β”‚   β”‚   β”‚   β”‚   └── PharmacyDashboard.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Admin/
β”‚   β”‚   β”‚   β”‚   └── AdminDashboard.jsx
β”‚   β”‚   β”‚   └── Patients/
β”‚   β”‚   β”‚       β”œβ”€β”€ PatientList.jsx
β”‚   β”‚   β”‚       β”œβ”€β”€ PatientProfile.jsx
β”‚   β”‚   β”‚       └── PatientRegistration.jsx
β”‚   β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”‚   └── api.js           # Axios instance
β”‚   β”‚   β”œβ”€β”€ App.jsx              # Main app component
β”‚   β”‚   β”œβ”€β”€ main.jsx             # React entry point
β”‚   β”‚   └── index.css            # Global styles
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ vite.config.js
β”‚   └── tailwind.config.js
└── database/
    β”œβ”€β”€ schema.sql               # Database schema
    └── seed.sql                 # Sample data

πŸ” Security Features

  • JWT Authentication: Secure token-based authentication
  • Password Hashing: bcrypt with salt rounds
  • Role-Based Access Control: 5 distinct user roles with specific permissions
  • Audit Logging: All patient data access is logged
  • Input Validation: Protection against SQL injection
  • CORS: Configured for secure cross-origin requests
  • Helmet: Security headers for Express

🎯 User Roles & Permissions

Admin

  • User management (create, update, deactivate)
  • View audit logs
  • System configuration
  • Full patient access

Doctor

  • Register and manage patients
  • Create clinical notes (SOAP format)
  • Order lab tests
  • Create prescriptions
  • Create referrals
  • View all patient data

Nurse

  • View patients
  • Record vitals
  • Add care notes
  • View medical history

Lab Technician

  • View lab orders
  • Upload lab results
  • Create imaging records

Pharmacist

  • View prescriptions
  • Dispense medications
  • Track medication inventory

πŸ“Š Database Schema

The system uses a normalized MySQL database with 20+ tables:

  • users - System users with roles
  • patients - Patient demographics
  • medical_history - Past illnesses, surgeries, family history
  • diagnoses - Current and past diagnoses (ICD-style)
  • medications - Current and past medications
  • allergies - Drug and food allergies
  • clinical_notes - SOAP format documentation
  • treatment_plans - Treatment plans and follow-ups
  • lab_orders - Lab test orders
  • lab_results - Test results
  • imaging_records - X-ray, CT, MRI records
  • prescriptions - Electronic prescriptions
  • prescription_dispenses - Dispensing tracking
  • vitals - Patient vital signs
  • referrals - Referral management
  • external_shares - Data sharing tracking
  • audit_logs - Comprehensive audit trail

πŸ”„ API Endpoints

See API_DOCUMENTATION.md for complete API reference.

πŸ§ͺ Testing the Application

  1. Login: Use one of the default credentials
  2. Doctor Workflow:
    • Register a new patient
    • View patient profile
    • Add clinical notes
    • Order lab test
    • Create prescription
  3. Lab Workflow:
    • View pending lab orders
    • Upload results
  4. Pharmacy Workflow:
    • View prescription queue
    • Dispense medication
  5. Admin Workflow:
    • View audit logs
    • Manage users

πŸ“ Development

Backend Development

cd backend
npm run dev  # Uses nodemon for auto-reload

Frontend Development

cd frontend
npm run dev  # Vite dev server with HMR

Building for Production

# Frontend
cd frontend
npm run build

# Backend (no build needed, runs directly)
cd backend
NODE_ENV=production npm start

πŸ› Troubleshooting

Database Connection Issues

  • Verify MySQL is running
  • Check credentials in .env
  • Ensure database ehr_system exists

Port Already in Use

  • Backend: Change PORT in .env
  • Frontend: Change port in vite.config.js

CORS Errors

  • Ensure backend FRONTEND_URL matches frontend URL
  • Check CORS configuration in server.js

πŸ“„ License

MIT License - See LICENSE file for details

πŸ‘¨β€πŸ’» Support

For issues and questions, please create an issue in the repository.


Built with ❀️ for healthcare professionals

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages