From ff7d0a91370fa73a1c3d50b474854ac87778f345 Mon Sep 17 00:00:00 2001 From: Udo Waechter Date: Mon, 10 Nov 2025 19:39:11 +0100 Subject: [PATCH] initial --- app.py | 171 ++++++++++ index.html | 649 +++++++++++++++++++++++++++++++++++++ instance/health_tracker.db | Bin 0 -> 20480 bytes templates/add_record.html | 47 +++ templates/base.html | 428 ++++++++++++++++++++++++ templates/dashboard.html | 108 ++++++ templates/edit_record.html | 47 +++ templates/index.html | 20 ++ templates/login.html | 32 ++ templates/register.html | 36 ++ 10 files changed, 1538 insertions(+) create mode 100644 app.py create mode 100644 index.html create mode 100644 instance/health_tracker.db create mode 100644 templates/add_record.html create mode 100644 templates/base.html create mode 100644 templates/dashboard.html create mode 100644 templates/edit_record.html create mode 100644 templates/index.html create mode 100644 templates/login.html create mode 100644 templates/register.html diff --git a/app.py b/app.py new file mode 100644 index 0000000..ead334b --- /dev/null +++ b/app.py @@ -0,0 +1,171 @@ +# app.py +from flask import Flask, render_template, request, redirect, url_for, session, flash +from flask_sqlalchemy import SQLAlchemy +from datetime import datetime +import os + +app = Flask(__name__) +app.config['SECRET_KEY'] = 'your-secret-key-here' +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///health_tracker.db' +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False + +db = SQLAlchemy(app) + +# User model +class User(db.Model): + 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 = db.Column(db.String(120), nullable=False) + created_at = db.Column(db.DateTime, default=datetime.utcnow) + records = db.relationship('HealthRecord', backref='user', lazy=True) + +# Health record model +class HealthRecord(db.Model): + id = db.Column(db.Integer, primary_key=True) + user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) + illness_name = db.Column(db.String(200), nullable=False) + diagnosis_date = db.Column(db.Date, nullable=False) + severity = db.Column(db.String(20), nullable=False) + treatment = db.Column(db.String(300)) + description = db.Column(db.Text) + created_at = db.Column(db.DateTime, default=datetime.utcnow) + +# Create tables +with app.app_context(): + db.create_all() + +@app.route('/') +def index(): + if 'user_id' in session: + user = User.query.get(session['user_id']) + return redirect(url_for('dashboard', user=user)) + return render_template('index.html') + +@app.route('/register', methods=['GET', 'POST']) +def register(): + if request.method == 'POST': + username = request.form['username'] + email = request.form['email'] + password = request.form['password'] + + # Check if user already exists + existing_user = User.query.filter_by(username=username).first() + if existing_user: + flash('Username already exists', 'error') + return render_template('register.html') + + existing_email = User.query.filter_by(email=email).first() + if existing_email: + flash('Email already registered', 'error') + return render_template('register.html') + + # Create new user + new_user = User(username=username, email=email, password=password) + db.session.add(new_user) + db.session.commit() + + flash('Registration successful! Please log in.', 'success') + return redirect(url_for('login')) + + 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 = User.query.filter_by(username=username).first() + if user and user.password == password: + session['user_id'] = user.id + session['username'] = user.username + return redirect(url_for('dashboard')) + else: + flash('Invalid username or password', 'error') + + return render_template('login.html') + +@app.route('/logout') +def logout(): + session.pop('user_id', None) + session.pop('username', None) + flash('You have been logged out', 'info') + return redirect(url_for('index')) + +@app.route('/dashboard') +def dashboard(): + if 'user_id' not in session: + return redirect(url_for('login')) + + user = User.query.get(session['user_id']) + records = HealthRecord.query.filter_by(user_id=user.id).order_by(HealthRecord.diagnosis_date.desc()).all() + + # Calculate statistics + total_records = len(records) + recovered = sum(1 for record in records if 'recovered' in record.description.lower() or 'healed' in record.description.lower()) + active = total_records - recovered + + return render_template('dashboard.html', user=user, records=records, total_records=total_records, recovered=recovered, active=active) + +@app.route('/add_record', methods=['GET', 'POST']) +def add_record(): + if 'user_id' not in session: + return redirect(url_for('login')) + + if request.method == 'POST': + illness_name = request.form['illness_name'] + diagnosis_date = datetime.strptime(request.form['diagnosis_date'], '%Y-%m-%d') + severity = request.form['severity'] + treatment = request.form['treatment'] + description = request.form['description'] + + new_record = HealthRecord( + user_id=session['user_id'], + illness_name=illness_name, + diagnosis_date=diagnosis_date, + severity=severity, + treatment=treatment, + description=description + ) + + db.session.add(new_record) + db.session.commit() + + flash('Health record added successfully!', 'success') + return redirect(url_for('dashboard')) + + return render_template('add_record.html') + +@app.route('/edit_record/', methods=['GET', 'POST']) +def edit_record(record_id): + if 'user_id' not in session: + return redirect(url_for('login')) + + record = HealthRecord.query.get_or_404(record_id) + + # Verify user owns this record + if record.user_id != session['user_id']: + flash('Access denied', 'error') + return redirect(url_for('dashboard')) + + if request.method == 'POST': + record.illness_name = request.form['illness_name'] + record.diagnosis_date = datetime.strptime(request.form['diagnosis_date'], '%Y-%m-%d') + record.severity = request.form['severity'] + record.treatment = request.form['treatment'] + record.description = request.form['description'] + + db.session.commit() + flash('Health record updated successfully!', 'success') + return redirect(url_for('dashboard')) + + return render_template('edit_record.html', record=record) + +@app.route('/delete_record/', methods=['POST']) +def delete_record(record_id): + if 'user_id' not in session: + return redirect(url_for('login')) + + record = HealthRecord.query.get_or_404(record + diff --git a/index.html b/index.html new file mode 100644 index 0000000..f43bf33 --- /dev/null +++ b/index.html @@ -0,0 +1,649 @@ + + + + + + Health History Tracker + + + + +
+
+ +
+ + +
+
+ +
+ + +
+
+

Your Health Records

+ +
+ +
+
+ +

12

+

Total Illnesses

+
+
+ +

8

+

Recovered

+
+
+ +

4

+

Active Conditions

+
+
+ +

2.5y

+

Average Duration

+
+
+ +
+

Add New Health Record

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+ +
+ +
+
+

Recent Health Records

+
+ +
+
+ +
    +
  • +
    +

    Influenza (Flu)

    + Jan 15, 2023 +
    +
    +
    + + Severity: Moderate +
    +
    + + Treatment: Antiviral medication +
    +
    + + Duration: 7 days +
    +
    +

    Sudden onset with high fever, body aches, and fatigue. Recovered fully after 7 days with rest and antiviral medication.

    +
    + + +
    +
  • + +
  • +
    +

    Migraine Headache

    + Mar 3, 2023 +
    +
    +
    + + Severity: Severe +
    +
    + + Treatment: Triptans, rest in dark room +
    +
    + + Duration: 2 days +
    +
    +

    Severe throbbing pain on one side of head, nausea, sensitivity to light. Managed with prescribed triptans and rest.

    +
    + + +
    +
  • + +
  • +
    +

    Seasonal Allergies

    + Apr 12, 2023 +
    +
    +
    + + Severity: Mild +
    +
    + + Treatment: Antihistamines +
    +
    + + Duration: 3 weeks +
    +
    +

    Runny nose, sneezing, itchy eyes during spring season. Managed with over-the-counter antihistamines and avoiding allergens.

    +
    + + +
    +
  • +
+
+
+
+ +
+

Health History Tracker © 2023 | All your health records in one place

+
+
+ + + + diff --git a/instance/health_tracker.db b/instance/health_tracker.db new file mode 100644 index 0000000000000000000000000000000000000000..47f6bac0dc7051f4c52f150e41122b051c59482a GIT binary patch literal 20480 zcmeI(Z*S5-90%}gflWwQw=4@!FIg5KafFt^5T6X^ZK901u9)pnQ|T#9fNpK)zh`QE z3%&#&`$9~73wsOt$oR;+PUcv`j89CQ-%IXj?|#?b??d|FNZH?Odl9Ek{9x!rv_j^I zqL2+r2_Z>QQ=*QGDh_1dxG3X;D?XE?^y)aPeIv>2eKPk^`>cHs2PhDL00bZa0SG_< z0uX=z1paA(H@)O+E}vK4r6T9?fcLpGi28QGdw$?foTN5Q*0dP4ns?faP7KjPChfVj z)v?$%GihhnqMdHLeUoO=Cm|2)DP!JXFydiokDMW=kDBJ@y{1_(%H`t36X!T)acbpYgzpUS7DuPR4FT&%2*s|NsN#w`pwoKPHWSh*ZzYWx7U_v}< zH{|1%6;;*V6YY~|P#^#S2tWV=5P$##AOHafKmY;|_=^H->I_+2$u(WyaQzL@mU?~1 z4_#k3Dn{9;uIl=#UZ#4zVU!!ydZ|`3)(yi@X2`;_oE1-+I!9k`RMtw>TD4Zcl@VE~ z+E=1|7YzyoAOHafKmY;|fB*y_009U<00P%UU^cO+h+h=cRAM3R`e*z9Q=)y*POnLV zNCN^8fB*y_009U<00Izz00bcL-wDhoR>W@q*DD0-Tw+;l`$fmu>jCopfAOb(6bL{7 X0uX=z1Rwwb2tWV=5P$##uCc%mhZp}c literal 0 HcmV?d00001 diff --git a/templates/add_record.html b/templates/add_record.html new file mode 100644 index 0000000..16d8d95 --- /dev/null +++ b/templates/add_record.html @@ -0,0 +1,47 @@ + +{% extends "base.html" %} + +{% block title %}Add Health Record - Health History Tracker{% endblock %} + +{% block content %} +
+
+
+

Add New Health Record

+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+ + Cancel +
+
+
+
+{% endblock %} diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..02fdb9e --- /dev/null +++ b/templates/base.html @@ -0,0 +1,428 @@ + + + + + + + {% block title %}Health History Tracker{% endblock %} + + + + + +
+
+ + {% if session.user_id %} +
+ + Logout +
+ {% endif %} +
+ + {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} + {% for category, message in messages %} + + {% endfor %} + {% endif %} + {% endwith %} + + {% block content %}{% endblock %} + +
+

Health History Tracker © 2023 | All your health records in one place

+
+
+ + + + + diff --git a/templates/dashboard.html b/templates/dashboard.html new file mode 100644 index 0000000..74103a4 --- /dev/null +++ b/templates/dashboard.html @@ -0,0 +1,108 @@ + +{% extends "base.html" %} + +{% block content %} +
+ + +
+
+
+

Your Health Records

+ + Add New Record + +
+ +
+
+ +

{{ total_records }}

+

Total Illnesses

+
+
+ +

{{ recovered }}

+

Recovered

+
+
+ +

{{ active }}

+

Active Conditions

+
+
+ +

2.5y

+

Average Duration

+
+
+ + {% if records %} +
+
+

Recent Health Records

+
+ +
+
+ +
    + {% for record in records %} +
  • +
    +

    {{ record.illness_name }}

    + {{ record.diagnosis_date.strftime('%b %d, %Y') }} +
    +
    +
    + + Severity: {{ record.severity.title() }} +
    +
    + + Treatment: {{ record.treatment or 'None' }} +
    +
    + + Duration: {{ 'Unknown' }} +
    +
    +

    {{ record.description[:150] }}{% if record.description|length > 150 %}...{% endif %}

    +
    + Edit +
    + +
    +
    +
  • + {% endfor %} +
+
+ {% else %} +
+ +

No Health Records Found

+

You haven't added any health records yet. Start by adding your first record.

+ + Add Your First Record + +
+ {% endif %} +
+
+
+{% endblock %} diff --git a/templates/edit_record.html b/templates/edit_record.html new file mode 100644 index 0000000..c8d144d --- /dev/null +++ b/templates/edit_record.html @@ -0,0 +1,47 @@ + +{% extends "base.html" %} + +{% block title %}Edit Health Record - Health History Tracker{% endblock %} + +{% block content %} +
+
+
+

Edit Health Record

+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+ + Cancel +
+
+
+
+{% endblock %} diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..1404649 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,20 @@ + +{% extends "base.html" %} + +{% block content %} +
+
+

Welcome to Health History Tracker

+

Track and manage your health records with our secure platform.

+
+ {% if session.user_id %} + Go to Dashboard + Logout + {% else %} + Login + Register + {% endif %} +
+
+
+{% endblock %} diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..3baff9b --- /dev/null +++ b/templates/login.html @@ -0,0 +1,32 @@ + +{% extends "base.html" %} + +{% block title %}Login - Health History Tracker{% endblock %} + +{% block content %} +
+
+
+
+

Login to Your Account

+
+
+
+
+ + +
+
+ + +
+ +
+
+

Don't have an account? Register here

+
+
+
+
+
+{% endblock %} diff --git a/templates/register.html b/templates/register.html new file mode 100644 index 0000000..3648ce2 --- /dev/null +++ b/templates/register.html @@ -0,0 +1,36 @@ + +{% extends "base.html" %} + +{% block title %}Register - Health History Tracker{% endblock %} + +{% block content %} +
+
+
+
+

Create Account

+
+
+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+

Already have an account? Login here

+
+
+
+
+
+{% endblock %}