A comprehensive hospital records management system built for Namulundu Hospital to efficiently manage patient records, medical books, billing, and data exports with intelligent search capabilities.
- Features
- Tech Stack
- Project Structure
- Installation
- Configuration
- Usage
- API Endpoints
- Database Schema
- Backup System
- Deployment
- Contributing
- License
- Patient Management: Add, search, and manage patient records with detailed medical information
- Book/File Management: Organize patient records by book numbers with contact information and billing
- Billing System: Track consultation fees and cumulative book balances
- Search Functionality: Search patients by name or book number with reinforcement-based ranking
- Authentication: Secure session-based login system
- CSV Export: Export all patient records to CSV format
- PDF Export: Generate professional PDF reports with hospital branding
- Similarity Scoring: TF-IDF based similarity search using scikit-learn
- Reinforcement Learning: Memory reinforcement engine that improves search relevance over time
- Automated Backups: Daily backup generation in CSV and PDF formats
- Google Drive Integration: Automatic upload of backups to Google Drive
| Component | Technology |
|---|---|
| Backend | Python 3.10, Flask 2.3.3 |
| Database | SQLAlchemy ORM (SQLite/PostgreSQL) |
| Frontend | HTML5, Bootstrap 5.3, Jinja2 Templates |
| ML/Search | scikit-learn (TF-IDF, Cosine Similarity) |
| PDF Generation | ReportLab |
| Cloud Backup | PyDrive (Google Drive API) |
| Production Server | Gunicorn |
NeuroSim/
├── app.py # Main Flask application
├── auth.py # Authentication blueprint
├── backup.py # Automated backup system with Google Drive
├── requirements.txt # Python dependencies
├── Procfile # Heroku deployment configuration
├── runtime.txt # Python version specification
│
├── db/
│ └── orm.py # SQLAlchemy ORM models and database operations
│
├── engine/
│ ├── memory_engine.py # Core memory/record management engine
│ ├── similarity.py # TF-IDF similarity scoring
│ └── reinforcement.py # Reinforcement learning for search ranking
│
├── utils/
│ ├── csv_export.py # CSV export functionality
│ └── pdf_export.py # PDF report generation
│
├── templates/
│ ├── index.html # Home page/dashboard
│ ├── login.html # Login page
│ ├── patients.html # Patient data entry form
│ ├── books.html # Books listing and management
│ ├── search.html # Patient search results
│ └── edit_bill.html # Bill editing interface
│
├── backups/ # Local backup storage
└── archive/ # Archived records
- Python 3.10 or higher
- pip (Python package manager)
- Git
-
Clone the repository
git clone https://github.com/sp-mujuni/NeuroSim.git cd NeuroSim -
Create a virtual environment
python -m venv venv # Windows venv\Scripts\activate # macOS/Linux source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Run the application
python app.py
-
Access the application Open your browser and navigate to
http://127.0.0.1:5000
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
Database connection string | sqlite:///namulundu.db |
SECRET_KEY |
Flask session secret key | your-secret-key |
The application supports both SQLite (development) and PostgreSQL (production):
# SQLite (default for development)
DATABASE_URL=sqlite:///namulundu.db
# PostgreSQL (production)
DATABASE_URL=postgresql://user:password@host:port/databaseTo enable Google Drive backup:
- Create a Google Cloud project and enable the Drive API
- Download OAuth credentials as
client_secrets.json - Create a
settings.yamlfile for PyDrive configuration - Run
backup.pyfor first-time authentication
| Username | Password |
|---|---|
admin |
neurosim123 |
⚠️ Important: Change these credentials in production by modifyingauth.py
- Navigate to Patients from the home page
- Fill in the required fields:
- Book Number: Unique identifier for the patient's record book
- Book Contact: Contact number associated with the book
- Patient Name: Full name of the patient
- Condition: Medical condition or diagnosis
- Notes: Detailed medical notes
- Prescription: Prescribed medications and treatments
- Consultation Fee: Fee for the current visit (UGX)
- Doctor: Attending physician's name
- Doctor's Contact: Physician's contact number
- Click Save to add the record
- Navigate to Books from the home page
- View all book records with their current balances
- Search for specific books using the search bar
- Click Update Bill to modify a book's balance
- Navigate to Search Patients from the patients page
- Enter a patient name or book number
- View matching results with full medical details
- Print results directly from the browser
From the Books page:
- Click Export All (CSV) for spreadsheet format
- Click Export All (PDF) for printable reports
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
GET |
/ |
Home dashboard | ✅ |
GET |
/login |
Login page | ❌ |
POST |
/login |
Process login | ❌ |
GET |
/logout |
Logout user | ❌ |
GET |
/patients |
Patient entry form | ✅ |
POST |
/add |
Add new patient record | ✅ |
GET |
/books |
List all books | ✅ |
GET |
/bill/<book_id> |
Edit bill form | ✅ |
POST |
/bill/<book_id> |
Update bill | ✅ |
GET |
/search?query= |
Search patients | ✅ |
GET |
/export/all/csv |
Export CSV | ✅ |
GET |
/export/all/pdf |
Export PDF | ✅ |
| Column | Type | Description |
|---|---|---|
id |
String (PK) | Unique UUID identifier |
book_id |
String | Book/file number |
name |
String | Patient name |
condition |
String | Medical condition |
content |
Text | Full medical notes, prescription, fees |
book_balance |
Float | Cumulative balance (default: 0.0) |
book_contact |
String | Contact number for the book |
doctor |
String | Attending doctor's name |
doctor_contact |
String | Doctor's contact number |
timestamp |
DateTime | Record creation/update timestamp |
The backup system (backup.py) provides:
- Daily CSV and PDF backup generation
- Timestamped filenames:
backup_records_YYYY-MM-DD.csv/pdf - Automatic Google Drive upload to "Namulundu" folder
python backup.pyWindows (Task Scheduler):
schtasks /create /tn "NamulunduBackup" /tr "python C:\path\to\backup.py" /sc daily /st 23:00Linux/macOS (Cron):
# Add to crontab (crontab -e)
0 23 * * * /path/to/venv/bin/python /path/to/backup.pyThe application is configured for Heroku deployment:
-
Procfile: Configured to use Gunicorn
web: gunicorn app:app -
Runtime: Python 3.10.13
python-3.10.13 -
Deploy to Heroku:
heroku create namulundu-hospital heroku addons:create heroku-postgresql:mini git push heroku main
Set these in your production environment:
DATABASE_URL=postgresql://...
SECRET_KEY=<secure-random-key>Core engine for CRUD operations on patient records with in-memory caching and database persistence.
Uses TF-IDF vectorization and cosine similarity to find the most relevant patient records based on search queries. Returns top 5 matching results.
Implements a reinforcement learning mechanism that increases the "strength" of frequently accessed records, improving search relevance over time.
# Learning formula
new_strength = old_strength + learning_rate * (1.0 - old_strength)- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support, please contact the development team or open an issue on GitHub.
Namulundu Hospital - "Comprehensive Care for All"
Built with ❤️ for healthcare management