Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 37 additions & 29 deletions app-backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ class Therapist(db.Model):
is_available = db.Column(db.Boolean, default=True)
patients_treated = db.Column(db.Integer, default=0)
patients_queue = db.Column(db.Integer, default=0)

about = db.Column(db.Text, nullable=True)
description = db.Column(db.Text, nullable=True)
specialization = db.Column(db.Text, nullable=True)
rating = db.Column(db.Integer, nullable=True)
experience = db.Column(db.Text,nullable=True)
feedbacks = db.relationship('Feedback', backref='therapists', lazy=True)


Expand Down Expand Up @@ -360,7 +364,6 @@ class Meta:
@app.route('/signup', methods=['POST'])
def signup():
data = request.get_json()
print("data",data)
fname = data.get('fname')
lname = data.get('lname')
email = data.get('email')
Expand Down Expand Up @@ -504,7 +507,7 @@ def generate_response():
if chatt:
chatt.title = title
db.session.commit()
print(f"Chat updated with title: {chatt.title}")

if not data or 'user_input' not in data:
return jsonify({"error": "Please say something"}), 400
user_input = data.get('user_input', 'I am not feeling well')
Expand Down Expand Up @@ -613,8 +616,7 @@ def delete_chat():

@app.route("/contact_us", methods=["POST"])
def contact_us():
# print(f"Form Data: {request.form}")
# if request.method == "POST":

try:
data = request.get_json()
name = data.get('name')
Expand Down Expand Up @@ -650,8 +652,6 @@ def contact_us():
db.session.add(new_query)
db.session.commit()

# print(new_query)
print(name)
return jsonify({"status": "success"}), 200
except Exception as e:
print(f'Error: {e}, Trace: {traceback.format_exc()}')
Expand Down Expand Up @@ -893,6 +893,24 @@ def list_reviews():

return jsonify(review_list), 200

@app.route('/list_queries', methods=['GET'])
def list_queries():
queries = db.session.query(ContactUs).all()

query_list = [
{
"id": q.id,
"name": q.name,
"email": q.email,
"query": q.query,
"contacted_on": q.contacted_on
}
for q in queries
]
print(query_list)

return jsonify(query_list), 200



@app.route('/create_therapist', methods=['POST'])
Expand Down Expand Up @@ -921,24 +939,21 @@ def create_therapist():

@app.route('/list_therapists', methods=['GET'])
def list_therapists():

therapists = db.session.query(Therapist).all()

therapist_list = [
{
"id": therapist.id,
"name": therapist.name,
"designation": therapist.designation,
"qualification": therapist.qualification,
"location": therapist.location,
"is_available": therapist.is_available,
"patients_treated": therapist.patients_treated,
"patients_queue": therapist.patients_queue
}
for therapist in therapists
result = [
{c.name: getattr(t, c.name) for c in t.__table__.columns}
for t in therapists
]
return jsonify(result), 200

@app.route('/get_therapist/<int:id>', methods=['GET'])
def get_therapist(id):
therapist = db.session.query(Therapist).get(id)
if therapist is None:
return jsonify({'error': 'Therapist not found'}), 404

return jsonify(therapist_list), 200
result = {c.name: getattr(therapist, c.name) for c in therapist.__table__.columns}
return jsonify(result), 200


@app.route('/edit_therapist/<int:therapist_id>', methods=['PUT'])
Expand Down Expand Up @@ -1253,11 +1268,8 @@ def add_journal():

try:
prompt = f"Analyze the following journal and determine the mood. Just give a single word answer.Mood must be among these [\"happy\", \"sad\", \"angry\", \"calm\", \"stressed\", \"excited\", \"bored\", \"anxious\", \"content\"].Just give a single word answer.\nJournal: {text}"
print(1,prompt)
response = model.generate_content(prompt)
print(2,response)
detected_mood = response.candidates[0].content.parts[0].text.strip() if response.candidates else "Neutral"
print(3,detected_mood)
except Exception as e:
detected_mood = "Unknown"

Expand Down Expand Up @@ -2358,15 +2370,13 @@ def alot_coupons():
def update_profile():
try:
data = request.get_json()
print("data",data)
client_id = data.get('client_id')
if not client_id:
return jsonify({"error": "Client ID is required"}), 400

user = db.session.get(User, client_id)
if not user:
return jsonify({"error": "User not found"}), 404
print(2)
if 'fname' in data:
user.first_name = data['fname']
if 'lname' in data:
Expand All @@ -2375,10 +2385,8 @@ def update_profile():
user.phone = data['phone']
if 'religion' in data:
user.religion = data['religion']
print(3)
user.updated_at = datetime.now(timezone.utc)
db.session.commit()
print(user)
return jsonify({"message": "Profile updated successfully"}), 200

except Exception as e:
Expand Down
Binary file modified app-backend/instance/eunoia.db
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""add 4 columns to therapist table

Revision ID: 01480a35f8d5
Revises: e23fd24ef6fe
Create Date: 2025-05-22 19:15:20.005443

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '01480a35f8d5'
down_revision = 'e23fd24ef6fe'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('therapists', schema=None) as batch_op:
batch_op.add_column(sa.Column('specialization', sa.Text(), nullable=True))
batch_op.add_column(sa.Column('about', sa.Text(), nullable=True))
batch_op.add_column(sa.Column('rating', sa.Text(), nullable=True))
batch_op.add_column(sa.Column('description', sa.Text(), nullable=True))

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('therapists', schema=None) as batch_op:
batch_op.drop_column('description')
batch_op.drop_column('rating')
batch_op.drop_column('about')
batch_op.drop_column('specialization')

# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""add experience column to therapist table

Revision ID: 5827c077fcb2
Revises: 01480a35f8d5
Create Date: 2025-05-22 20:29:16.719588

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '5827c077fcb2'
down_revision = '01480a35f8d5'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('therapists', schema=None) as batch_op:
batch_op.add_column(sa.Column('experience', sa.Text(), nullable=True))
batch_op.alter_column('rating',
existing_type=sa.TEXT(),
type_=sa.Integer(),
existing_nullable=True)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('therapists', schema=None) as batch_op:
batch_op.alter_column('rating',
existing_type=sa.Integer(),
type_=sa.TEXT(),
existing_nullable=True)
batch_op.drop_column('experience')

# ### end Alembic commands ###
52 changes: 38 additions & 14 deletions app-backend/update_therapists.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ class Therapist(db.Model):
is_available = db.Column(db.Boolean, default=True)
patients_treated = db.Column(db.Integer, default=0)
patients_queue = db.Column(db.Integer, default=0)
# about = db.Column(db.Text, nullable=True)
# description = db.Column(db.Text, nullable=True)
# specialization = db.Column(db.Text, nullable=True)
# rating = db.Column(db.Integer, nullable=True)
about = db.Column(db.Text, nullable=True)
description = db.Column(db.Text, nullable=True)
specialization = db.Column(db.Text, nullable=True)
rating = db.Column(db.Integer, nullable=True)
experience = db.Column(db.Text, nullable=True)

def generate_therapist_info(therapist):
prompt = f"""
Expand All @@ -48,10 +49,11 @@ def generate_therapist_info(therapist):
Return a JSON object in this exact format without any markdown formatting or additional text:
{{
"location": "<randomly choose: Lahore, Karachi, or Islamabad>",
"rating": <randomly choose: 3, 4, or 5>,
"rating": <randomly choose one value : 3, 4, or 5>,
"description": "<2-3 sentences about their practice>",
"about": "<3-4 sentences about their background>",
"specialization": "<2-3 mental health specialties>"
"specialization": "<2-3 mental health specialties>",
"experience":"<Give a random 'x-y' string where x is 1-4 and y = x + 1>"
}}
"""

Expand Down Expand Up @@ -80,11 +82,12 @@ def generate_therapist_info(therapist):
'rating': random.randint(3, 5),
'description': 'Experienced therapist providing compassionate care and evidence-based treatment.',
'about': 'Dedicated mental health professional with years of experience in helping clients achieve emotional well-being.',
'specialization': ', '.join(random.sample(specialties, 2))
'specialization': ', '.join(random.sample(specialties, 2)),
'experience':'1-2'
}

def update_therapists():
with app.app_context():
with app.app_context():
therapists = Therapist.query.all()
print(f"Found {len(therapists)} therapists")

Expand All @@ -97,13 +100,34 @@ def update_therapists():
info = generate_therapist_info(therapist)
if info:
try:
therapist.location = info.get('location')
therapist.rating = info.get('rating')
therapist.description = info.get('description')
therapist.about = info.get('about')
therapist.specialization = info.get('specialization')
# Always use random choice for rating to ensure variability
therapist.rating = random.choice([3, 4, 5])
# Process other fields
therapist.location = info.get('location', random.choice(['Lahore', 'Karachi', 'Islamabad']))
therapist.description = info.get('description', 'Experienced therapist providing compassionate care.')
therapist.about = info.get('about', 'Dedicated mental health professional.')

# Handle specialization which might come as list or string
specs = info.get('specialization')
if isinstance(specs, list):
specs = ', '.join(specs)
elif not specs:
specs = random.choice([
'Anxiety & Depression, Stress Management',
'Cognitive Behavioral Therapy, Trauma Recovery',
'Family Counseling, Mental Wellness'
])
therapist.specialization = specs

# Handle experience
exp = info.get('experience')
if not exp:
x = random.randint(1, 4)
exp = f"{x}-{x+1}"
therapist.experience = exp

db.session.commit()
print(f"Successfully updated {therapist.name} with: {info}")
print(f"Successfully updated {therapist.name} with rating: {therapist.rating}")
except Exception as e:
print(f"Error updating database for {therapist.name}: {str(e)}")
db.session.rollback()
Expand Down
Loading