help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
healthcare-assistant-bot
RSK World
healthcare-assistant-bot
Healthcare Assistant Bot - Python + Flask + SQLite + PHP Dashboard + NLP + Medical Features
healthcare-assistant-bot
  • static
  • templates
  • .dockerignore83 B
  • .gitignore114 B
  • Dockerfile510 B
  • LICENSE1.1 KB
  • README.md4.1 KB
  • RELEASE_NOTES.md814 B
  • app.py4.8 KB
  • appointments.py456 B
  • database.py2.5 KB
  • image_prompts.txt1.7 KB
  • reminders.py409 B
  • requirements.txt54 B
  • symptoms.py897 B
STATUS_REPORT.mdconversation_history.jsonLICENSEapp.py
LICENSE
Raw Download
Find: Go to:
MIT License

Copyright (c) 2026 Molla Samser (info@rskworld.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 lines•1.1 KB
text
app.py
Raw Download
Find: Go to:
#
# Project: Healthcare Assistant Bot
# Author: Molla Samser
# Author's Email: info@rskworld.com
# Author's Phone: +91 93305 39277
# Author's Website: https://rskworld.in
# Year: 2026
#

from flask import Flask, render_template, request, jsonify, redirect, url_for, session, flash
from database import init_db, add_user, get_user_by_username, get_all_appointments, get_all_reminders
from appointments import schedule_appointment
from symptoms import check_symptoms
from reminders import set_reminder
from werkzeug.security import generate_password_hash, check_password_hash
from functools import wraps
import re

app = Flask(__name__)
app.secret_key = 'your_secret_key' # Replace with a strong secret key

# Initialize the database
init_db()

# Decorator to restrict access to admin users
def admin_required(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        if 'username' not in session:
            flash('Please login to access this page.', 'warning')
            return redirect(url_for('login'))
        user = get_user_by_username(session['username'])
        if user and user[4] != 'admin': # user[4] is the role
            flash('You do not have administrative privileges.', 'danger')
            return redirect(url_for('index'))
        return f(*args, **kwargs)
    return decorated_function

@app.route('/')
def index():
    if 'username' not in session:
        return redirect(url_for('login'))
    return render_template('index.html', username=session['username'])

@app.route('/register', methods=['GET', 'POST'])
def register():
    if request.method == 'POST':
        username = request.form['username']
        email = request.form['email']
        password = request.form['password']
        
        hashed_password = generate_password_hash(password, method='pbkdf2:sha256')
        
        try:
            add_user(username, email, hashed_password) # Default role is 'user'
            flash('Registration successful! Please login.', 'success')
            return redirect(url_for('login'))
        except Exception as e:
            flash(f'Registration failed: {e}', 'danger')
    return render_template('register.html')

@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        
        user = get_user_by_username(username)
        
        if user and check_password_hash(user[3], password): # user[3] is the hashed password
            session['username'] = user[1] # user[1] is the username
            session['role'] = user[4] # user[4] is the role
            flash('Login successful!', 'success')
            return redirect(url_for('index'))
        else:
            flash('Login failed. Please check your username and password.', 'danger')
    return render_template('login.html')

@app.route('/logout')
def logout():
    session.pop('username', None)
    session.pop('role', None) # Clear role from session
    flash('You have been logged out.', 'info')
    return redirect(url_for('login'))

@app.route('/admin')
@admin_required
def admin_dashboard():
    appointments = get_all_appointments()
    reminders = get_all_reminders()
    return render_template('admin.html', appointments=appointments, reminders=reminders)

@app.route('/chat', methods=['POST'])
def chat():
    if 'username' not in session:
        return jsonify({'response': 'Please login to use the chat.'}), 401
    
    user_message = request.json.get('message')
    
    # NLP and intent recognition
    if re.search(r'schedule an appointment', user_message, re.IGNORECASE):
        # Example of extracting date and time, should be more robust
        match = re.search(r'(\d{1,2}/\d{1,2}/\d{4}) at (\d{1,2}:\d{2})', user_message)
        if match:
            date, time = match.groups()
            bot_response = schedule_appointment(date, time, f"General Checkup for {session['username']}")
        else:
            bot_response = "Please provide a date and time for the appointment in the format MM/DD/YYYY at HH:MM."
    elif re.search(r'symptoms of', user_message, re.IGNORECASE):
        symptoms = user_message.split("symptoms of")[1].strip()
        bot_response = check_symptoms(symptoms)
    elif re.search(r'remind me to take', user_message, re.IGNORECASE):
        match = re.search(r'remind me to take (.+) at (\d{1,2}:\d{2})', user_message, re.IGNORECASE)
        if match:
            medication, time = match.groups()
            bot_response = set_reminder(medication, time)
        else:
            bot_response = "Please tell me the medication and time for the reminder."
    else:
        bot_response = "I am a healthcare assistant bot. You can ask me to schedule an appointment, check your symptoms, or set a medication reminder."
        
    return jsonify({'response': bot_response})

if __name__ == '__main__':
    app.run(debug=True)
126 lines•4.8 KB
python
🚀 Support RSK World

Subscribe to our YouTube channel for latest tutorials & updates!



Click subscribe & support our work ❤️

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer