-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,482 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from flask import Flask | ||
from flask_sqlalchemy import SQLAlchemy | ||
from flask_socketio import SocketIO, emit | ||
import os | ||
|
||
|
||
|
||
app = Flask(__name__) | ||
|
||
app.secret_key = os.getenv('SECRET_KEY') | ||
|
||
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATEABASE_URL') | ||
|
||
|
||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | ||
|
||
|
||
db = SQLAlchemy(app) | ||
|
||
from . import routes | ||
app.register_blueprint(routes.bp) | ||
socketio = SocketIO(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from flask import redirect, url_for, session, jsonify, request | ||
from functools import wraps | ||
|
||
ROLES = { | ||
1 : 'admin', | ||
2 : 'caregiver', | ||
3 : 'patient' | ||
} | ||
|
||
ROLES_REV = { | ||
'admin' : 1, | ||
'caregiver' : 2, | ||
'patient' : 3 | ||
} | ||
ROLES_URL = { | ||
'admin' : '/', | ||
'caregiver' : '/caregiver_dashboard', | ||
'patient' : '/patient_dashboard' | ||
} | ||
|
||
|
||
|
||
def role_required(role): | ||
"""Decorator to restrict access based on user role.""" | ||
def decorator(func): | ||
@wraps(func) | ||
def wrapped_view(*args, **kwargs): | ||
if 'id' not in session: | ||
return redirect('/') | ||
user_role = session.get('role') | ||
if user_role != role: | ||
|
||
if request.is_json: | ||
return jsonify({"error": "Access denied"}), 403 | ||
|
||
return redirect('/unauthorized_access') | ||
return func(*args, **kwargs) | ||
return wrapped_view | ||
return decorator | ||
|
||
def roles_required(*roles): | ||
"""Decorator to allow multiple roles access to a route.""" | ||
def decorator(func): | ||
@wraps(func) | ||
def wrapped_view(*args, **kwargs): | ||
user_role = session.get('role') | ||
if user_role not in roles: | ||
if request.is_json: | ||
return jsonify({"error": "Access denied"}), 403 | ||
return redirect(url_for('unauthorized_access')) | ||
return func(*args, **kwargs) | ||
return wrapped_view | ||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from . import db | ||
from datetime import datetime | ||
|
||
|
||
class User(db.Model): | ||
__tablename__ = 'users' | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
username = db.Column(db.String(80), unique=True, nullable=False) | ||
email = db.Column(db.String(120), unique=True, nullable=False) | ||
password_hash = db.Column(db.String(128), nullable=False) | ||
role = db.Column(db.String(50), nullable=False, default="patient") | ||
created_at = db.Column(db.DateTime, default=datetime.now) | ||
verified = db.Column(db.Boolean, default = False) | ||
|
||
def __repr__(self): | ||
return f"<User {self.username}>" | ||
|
||
|
||
class Patient(db.Model): | ||
__tablename__ = 'patients' | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
name = db.Column(db.String(120), nullable=False) | ||
address = db.Column(db.String(255), nullable=True) | ||
medical_records = db.Column(db.Text, nullable=True) | ||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) | ||
caregiver_id = db.Column(db.Integer, db.ForeignKey('caregivers.id'), nullable=True) | ||
|
||
def __repr__(self): | ||
return f"<Patient {self.name}>" | ||
|
||
|
||
class Caregiver(db.Model): | ||
__tablename__ = 'caregivers' | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
name = db.Column(db.String(120), nullable=False) | ||
availability = db.Column(db.Boolean, default=True) | ||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) | ||
|
||
patients = db.relationship('Patient', backref='caregiver', lazy=True) | ||
def __repr__(self): | ||
return f"<Caregiver {self.name}>" | ||
|
||
class Appointment(db.Model): | ||
__tablename__ = 'appointments' | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
patient_id = db.Column(db.Integer, db.ForeignKey('patients.id'), nullable=False) | ||
caregiver_id = db.Column(db.Integer, db.ForeignKey('caregivers.id'), nullable=False) | ||
appointment_date = db.Column(db.DateTime, nullable=False) | ||
updated_at = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now) | ||
|
||
patient = db.relationship('Patient', backref='appointments', lazy=True) | ||
caregiver = db.relationship('Caregiver', backref='appointments', lazy=True) | ||
|
||
def __repr__(self): | ||
return f"<Appointment {self.patient.name} with {self.caregiver.name} on {self.appointment_date}>" | ||
|
||
|
||
class Notification(db.Model): | ||
__tablename__ = 'notifications' | ||
|
||
id = db.Column(db.Integer, primary_key=True) | ||
recipient_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) | ||
message = db.Column(db.String(255), nullable=False) | ||
is_read = db.Column(db.Boolean, default=False) | ||
created_at = db.Column(db.DateTime, default=datetime.now) | ||
|
||
recipient = db.relationship('User', backref='notifications', lazy=True) | ||
|
||
def __repr__(self): | ||
return f"<Notification to User {self.recipient_id}: {self.message}>" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
bidict==0.23.1 | ||
blinker==1.9.0 | ||
click==8.1.7 | ||
Flask==3.1.0 | ||
Flask-SocketIO==5.4.1 | ||
Flask-SQLAlchemy==3.1.1 | ||
h11==0.14.0 | ||
itsdangerous==2.2.0 | ||
Jinja2==3.1.4 | ||
MarkupSafe==3.0.2 | ||
python-dotenv==1.0.1 | ||
python-engineio==4.10.1 | ||
python-socketio==5.11.4 | ||
simple-websocket==1.1.0 | ||
SQLAlchemy==2.0.36 | ||
typing_extensions==4.12.2 | ||
Werkzeug==3.1.3 | ||
wsproto==1.2.0 |
Oops, something went wrong.