def show_single_patient_posts(patient_id): """Show a patient's posts.""" user_type = get_user_type_from_session() page = request.args.get("page", 1, type=int) filter_date = request.args.get("date", None) filter_dates = get_months_years_of_patient_posts(patient_id) posts = get_single_patients_posts(patient_id, page, filter_date) patient = Patient.query.get(patient_id) if user_type == "dietitian": diet_and_pats = get_dietitian_and_patients_list() return render_template("dietitian-home-patient-posts.html", dietitian=diet_and_pats["dietitian"], patients=diet_and_pats["sorted_patients"], patient=patient, posts=posts, dates=filter_dates, date=filter_date) dietitian = patient.dietitian return render_template("patient-posts.html", patient=patient, dietitian=dietitian, posts=posts, dates=filter_dates, date=filter_date)
def add_post_comment(post_id, form_data): """Add a comment to a post in the database.""" time_stamp = datetime.now() comment_body = form_data.get("comment") user_type = get_user_type_from_session() if user_type == "patient": author_type = "pat" patient = get_current_patient() author_id = patient.patient_id else: author_type = "diet" dietitian = get_current_dietitian() author_id = dietitian.dietitian_id new_comment = Comment(post_id=post_id, author_type=author_type, author_id=author_id, time_stamp=time_stamp, comment_body=comment_body) db.session.add(new_comment) db.session.commit() return (new_comment)
def add_comments_to_post_dict(patient_id, comments, post_dict): """Add comments to a dictionary containing a post object.""" sorted_comments = sort_date_asc(comments) patient = Patient.query.get(patient_id) for comment in sorted_comments: if comment.author_type == "diet": author_fname = patient.dietitian.fname author_lname = patient.dietitian.lname else: author_fname = patient.fname author_lname = patient.lname edited = " (edited)" if comment.edited else "" user_type = get_user_type_from_session() if ((user_type == "dietitian" and comment.author_type == "diet") or (user_type == "patient" and comment.author_type == "pat")): is_author = True else: is_author = False post_dict["comments"][comment.comment_id] = { "comment_id": comment.comment_id, "author_fname": author_fname, "author_lname": author_lname, "comment_body": comment.comment_body, "time_stamp": comment.time_stamp.isoformat(), "edited": edited, "is_author": is_author } return post_dict
def decorated_view(*args, **kwargs): user_type = get_user_type_from_session() if user_type == "patient": patient = get_current_patient() return render_template("unauthorized.html", patient=patient) dietitian_id = kwargs["dietitian_id"] if not check_dietitian_authorization(dietitian_id): dietitian = get_current_dietitian() return render_template("unauthorized.html", dietitian=dietitian) return fn(*args, **kwargs)
def view_edit_patient_information_form(patient_id): """Edit a patient's basic information.""" user_type = get_user_type_from_session() patient = Patient.query.get(patient_id) if user_type == "dietitian": diet_and_pats = get_dietitian_and_patients_list() return render_template("dietitian-home-patient-edit.html", dietitian=diet_and_pats["dietitian"], patients=diet_and_pats["sorted_patients"], patient=patient) return render_template("patient-account-edit.html", patient=patient)
def show_single_patient_overview(patient_id): """Show information about a single patient.""" user_type = get_user_type_from_session() patient = Patient.query.get(patient_id) if user_type == "dietitian": diet_and_pats = get_dietitian_and_patients_list() return render_template("dietitian-home-patient-overview.html", dietitian=diet_and_pats["dietitian"], patients=diet_and_pats["sorted_patients"], patient=patient) return render_template("patient-account.html", patient=patient)
def get_ratings_chart_template(patient_id): """Shows page containing rating chart div.""" user_type = get_user_type_from_session() patient = Patient.query.get(patient_id) if user_type == "dietitian": diet_and_pats = get_dietitian_and_patients_list() return render_template("dietitian-ratings-chart.html", dietitian=diet_and_pats["dietitian"], patients=diet_and_pats["sorted_patients"], patient=patient) return render_template("patient-ratings-chart.html", patient=patient)
def decorated_view(*args, **kwargs): user_type = get_user_type_from_session() if user_type == "patient": patient = get_current_patient() return render_template("unauthorized.html", patient=patient) patient_id = kwargs["patient_id"] patient = Patient.query.get(patient_id) if not patient or (patient.dietitian_id != session.get("dietitian_id")): dietitian = get_current_dietitian() return render_template("unauthorized.html", dietitian=dietitian) return fn(*args, **kwargs)
def show_patient_goals(patient_id): """Show goals for a patient and allow dietitian to update goals.""" user_type = get_user_type_from_session() page = request.args.get("page", 1, type=int) goals = get_patients_goals_dict(patient_id, page) patient = Patient.query.get(patient_id) if user_type == "dietitian": diet_and_pats = get_dietitian_and_patients_list() return render_template("dietitian-home-patient-goals.html", dietitian=diet_and_pats["dietitian"], patients=diet_and_pats["sorted_patients"], patient=patient, current_goal=goals["current_goal"], past_goals=goals["past_goals"]) return render_template("patient-goals.html", patient=patient, goals=goals["all_goals"])
def decorated_view(*args, **kwargs): user_type = get_user_type_from_session() if user_type != "dietitian": patient = get_current_patient() return render_template("unauthorized.html", patient=patient) return fn(*args, **kwargs)
def decorated_view(*args, **kwargs): user_type = get_user_type_from_session() if user_type == "dietitian": patient_id = kwargs["patient_id"] return redirect(f"/patient/{patient_id}/account") return fn(*args, **kwargs)