Skip to content
Open
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
4 changes: 3 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ def register_blueprints(app):
from app.controllers.admin_controller import admin_bp
from app.controllers.new_requests_controller import upload_new_req_bp
from app.controllers.cases_controller import assign
from app.controllers.my_requests import my_req_bp
from app.controllers.my_cases import my_req_bp
from app.controllers.role_controller import role_bp
from app.controllers.analytics_controller import analytics_bp

app.register_blueprint(user_bp)
app.register_blueprint(admin_bp)
app.register_blueprint(upload_new_req_bp)
app.register_blueprint(assign)
app.register_blueprint(my_req_bp)
app.register_blueprint(role_bp)
app.register_blueprint(analytics_bp)
166 changes: 166 additions & 0 deletions app/controllers/analytics_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import logging
from datetime import datetime

from flask import Blueprint, request, jsonify, render_template
from flask_login import current_user
from sqlalchemy import text

from app import db

analytics_bp = Blueprint('analytics', __name__)

@analytics_bp.route('/analytics/get_years', methods = ['GET'])
def get_year_graphs():
year_data = []
query_for_get_years = """
select distinct(extract(year from outreach_date)) as year from cases order by year desc;
"""
with db.engine.connect() as connection:
result_get_years = connection.execute(
text(query_for_get_years))
for row in result_get_years:
year_data.append(row[0])

return jsonify({
'message': 'success',
'data': year_data
}), 200

@analytics_bp.route('/analytics/packets_sent', methods=['GET'])
def get_packets_sent_graph():
year = request.args.get('year')
month_data = [0] * 12
query_for_sent_packets = f"""
select extract(month from outreach_date) as month, count(id) from cases where
extract(year from outreach_date) = '{year}' group by month;
"""

with db.engine.connect() as connection:
result_sent_packets = connection.execute(
text(query_for_sent_packets))
for row in result_sent_packets:
month_data[int(row[0]) - 1] = row[1]

return jsonify({
'message': 'success',
'data': month_data
}), 200

@analytics_bp.route('/analytics/packets_status', methods=['GET'])
def get_packets_return_graph():
year = request.args.get('year')
return_status_data = [0] * 3
quey_for_packet_return_status = f"""
select count(id) from cases where
extract(year from outreach_date) = '{year}' group by packet_return_status order by packet_return_status asc;
"""
with db.engine.connect() as connection:
result_packet_return_status = connection.execute(
text(quey_for_packet_return_status))

i = 0
for row in result_packet_return_status:
return_status_data[i] = row[0]
i += 1

return jsonify({
'message': 'success',
'data': return_status_data
}), 200

@analytics_bp.route('/analytics/children_enrolled', methods=['GET'])
def get_children_enrolled_graph():
year = request.args.get('year')
children_enrolled_data = [0] * 12
query_for_children_enrolled = f"""
select extract(month from outreach_date) as month, sum(num_children_enrolled) from cases where
extract(year from outreach_date) = '{year}' group by month;
"""

with db.engine.connect() as connection:
result_children_enrolled = connection.execute(
text(query_for_children_enrolled))
for row in result_children_enrolled:
children_enrolled_data[int(row[0]) - 1] = row[1]

return jsonify({
'message': 'success',
'data': children_enrolled_data
}), 200

@analytics_bp.route('/analytics/children_not_enrolled', methods=['GET'])
def get_children_not_enrolled_enrolled():
year = request.args.get('year')
children_not_enrolled_data = [0] * 12
query_for_children_not_enrolled = f"""
select extract(month from outreach_date) as month, sum(num_of_children)-sum(num_children_enrolled) from cases where
extract(year from outreach_date) = '{year}' group by month;
"""

with db.engine.connect() as connection:
result_children_not_enrolled = connection.execute(
text(query_for_children_not_enrolled))
for row in result_children_not_enrolled:
children_not_enrolled_data[int(row[0]) - 1] = row[1]

return jsonify({
'message': 'success',
'data': children_not_enrolled_data
}), 200

@analytics_bp.route('/analytics/children_not_enrolled_reasons', methods=['GET'])
def get_not_enrolled_reasons_graph():
year = request.args.get('year')
not_enrolled_reasons_count = [0] * 15
not_enrolled_reasons = ["Does not meet employment/activity requirement", "Fee too high", "No Child Care Slots",
"No longer in Dallas County", "No longer needing services", "No packet received",
"No Provider Choice", "Not a Priority", "Not working/training", "On leave/STD",
"Over the income guidelines", "Unable to Reach Client", "Under participation requirement",
"Verification Docs Needed", "Other"
]
not_enrolled_reasons_dict = dict(
map(lambda i, j: (i, j), not_enrolled_reasons, not_enrolled_reasons_count))

query_for_not_enrolled_reason = f"""
select not_enrolled_reason, count(id) from cases where
extract(year from outreach_date) = '{year}' group by not_enrolled_reason having not_enrolled_reason <> '' order by not_enrolled_reason asc;
"""

with db.engine.connect() as connection:
result_not_enrolled_reason = connection.execute(
text(query_for_not_enrolled_reason))
for row in result_not_enrolled_reason:
not_enrolled_reasons_dict[str(row[0])] = row[1]

return jsonify({
'message': 'success',
'data': list(not_enrolled_reasons_dict.values())
}), 200

@analytics_bp.route('/analytics/processing_time', methods=['GET'])
def get_processing_time_graph():
year = request.args.get('year')
processing_time = [0] * 5

query_for_processing_time = f"""
select CASE
WHEN decision_date - outreach_date > 0 AND decision_date - outreach_date < 10 THEN 1
WHEN decision_date - outreach_date > 10 AND decision_date - outreach_date < 20 THEN 2
WHEN decision_date - outreach_date > 20 AND decision_date - outreach_date < 30 THEN 3
WHEN decision_date - outreach_date > 30 THEN 4
WHEN decision_date - outreach_date is NULL THEN 5
END Processing_Time, count(id) from cases where
extract(year from outreach_date) = '{year}' group by Processing_Time order by processing_time asc
;
"""

with db.engine.connect() as connection:
result_processing_time = connection.execute(
text(query_for_processing_time))
for row in result_processing_time:
processing_time[int(row[0]) - 1] = row[1]

return jsonify({
'message': 'success',
'data': processing_time
}), 200
93 changes: 93 additions & 0 deletions app/controllers/my_cases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
from datetime import datetime

from flask import jsonify
from flask import request, Blueprint, render_template
from flask_login import current_user
from flask_wtf import FlaskForm
from wtforms import StringField, IntegerField, SubmitField
from wtforms.fields import DateField

from app import db
from app.decorators.login_decorator import requires_login
from app.models import Case

my_req_bp = Blueprint('my-cases', __name__)


class RequestForm(FlaskForm):
id = IntegerField('ID')
customer_id = StringField('Customer ID')
first_name = StringField('First Name')
last_name = StringField('Last Name')
num_of_children = IntegerField('Number of Children')
outreach_date = DateField('Outreach Date')
packet_return_status = StringField('Packet Return Status')
packet_received_date = DateField('Packet Received Date')
staff_initials = StringField('Staff Initials')
decision = StringField('Decision')
num_children_enrolled = IntegerField('Number of Children Enrolled')
decision_date = DateField('Decision Date')
not_enrolled_reason = StringField('Not Enrolled Reason')
submit = SubmitField('Save Changes')


@requires_login
@my_req_bp.route('/my_cases', methods=['GET'])
def view_cases():
cases = current_user.user_cases
return render_template('my_cases.html', cases=cases, user=current_user)


@requires_login
@my_req_bp.route('/my_cases/edit/', methods=['POST'])
def edit_case():
data = request.json
num_children_enrolled = data.get('numChildrenEnrolled')

print(num_children_enrolled)
decision_date_str = data.get('decisionDate')
packet_received_date_str = data.get('packetReceivedDate')
case_id = data.get('caseId')
case_to_edit = Case.query.filter_by(id=case_id).first()

if not case_to_edit:
return jsonify({"status": "Error", "message": "Case not found"}), 404

outreach_date = case_to_edit.outreach_date
if num_children_enrolled != "":
try:
int(num_children_enrolled)
except:
return jsonify({"status": "Error", "message": "no. of children enrolled must be integer"}), 400
num_children_enrolled = int(
num_children_enrolled) if num_children_enrolled != "" else 0

try:
decision_date = datetime.strptime(
decision_date_str, '%Y-%m-%d') if decision_date_str and decision_date_str.lower() != 'none' else None
packet_received_date = datetime.strptime(
packet_received_date_str,
'%Y-%m-%d') if packet_received_date_str and packet_received_date_str.lower() != 'none' else None
except ValueError as e:
return jsonify({"status": "Error", "message": "Decision/Package dates must be valid dates"}), 400
print(decision_date, packet_received_date)
# Validate that decision and packet_received_date are not before outreach_date
if decision_date and decision_date.date() < outreach_date:
return jsonify({"status": "Error", "message": "Decision date cannot be before outreach date"}), 400

if packet_received_date and packet_received_date.date() < outreach_date:
return jsonify({"status": "Error", "message": "Packet received date cannot be before outreach date"}), 400

# Get the case ID from the data
case_to_edit.packet_return_status = data.get('packetReturnStatus')
case_to_edit.packet_received_date = data.get('packetReceivedDate')
case_to_edit.decision = data.get('decision')
case_to_edit.num_children_enrolled = num_children_enrolled
case_to_edit.decision_date = decision_date
case_to_edit.not_enrolled_reason = data.get('notEnrolledReason')

try:
db.session.commit()
return jsonify({"status": "OK"}), 200
except Exception as e:
return jsonify({"status": "Error", "message": e}), 400
57 changes: 0 additions & 57 deletions app/controllers/my_requests.py

This file was deleted.

2 changes: 1 addition & 1 deletion app/controllers/new_requests_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def populateDatabase(upload_file, file_path):
except Exception as e:
return jsonify({'message': 'Unsupported file format', 'error': str(e)}), 501

df = df.iloc[:, :5]
#df = df.iloc[:, :5]
df.rename(columns={'Outreach_Date': 'outreach_date'}, inplace=True)
valid_data, invalid_data = validateData(df)

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/user_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def send_mail(path, mailid, verification_code):
path = path.replace("admin/users", "user")
body = "Kindly follow the link to set your password for the Childcare Management System Account " + \
path + "/setPassword?user=" + verification_code
sender = "chidambaramg.dev@gmail.com"
password = "baeaqufrwmtosnnr"
sender = "childcaregroup9@gmail.com"
password = "krgbticpsttiyizy"
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = sender
Expand Down
27 changes: 27 additions & 0 deletions app/seeds/cases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from app import db
from app.models import Case
import logging


def seed():
my_case_1 = Case(customer_id="1", first_name="Tanmai", last_name="Harish", num_of_children=3,
outreach_date="2023-11-11")
my_case_2 = Case(customer_id="2", first_name="John", last_name="Jonhnson", num_of_children=2,
outreach_date="2023-11-12")
my_case_3 = Case(customer_id="3", first_name="Great", last_name="Khali", num_of_children=1,
outreach_date="2023-11-13")
my_case_4 = Case(customer_id="4", first_name="Daehee", last_name="Han", num_of_children=4,
outreach_date="2023-11-14")
my_case_5 = Case(customer_id="5", first_name="Ravi", last_name="Ashwin", num_of_children=5,
outreach_date="2023-11-15")
my_case_6 = Case(customer_id="6", first_name="Rajesh", last_name="Jadhav", num_of_children=3,
outreach_date="2023-11-16")
db.session.add(my_case_1)
db.session.add(my_case_2)
db.session.add(my_case_3)
db.session.add(my_case_4)
db.session.add(my_case_5)
db.session.add(my_case_6)
db.session.commit()

logging.info("Cases seeded")
Loading