-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
64 lines (47 loc) · 1.81 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from flask import Flask, render_template, request
import os
from dotenv import load_dotenv
from pandas import read_sql
from sqlalchemy import create_engine, text
load_dotenv() # Load environment variables from .env file
# Database connection settings from environment variables
DB_HOST = os.getenv("DB_HOST")
DB_DATABASE = os.getenv("DB_DATABASE")
DB_USERNAME = os.getenv("DB_USERNAME")
DB_PASSWORD = os.getenv("DB_PASSWORD")
DB_PORT = int(os.getenv("DB_PORT", 3306))
DB_CHARSET = os.getenv("DB_CHARSET", "utf8mb4")
# Connection string
connect_args={'ssl':{'fake_flag_to_enable_tls': True}}
connection_string = (f'mysql+pymysql://{DB_USERNAME}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_DATABASE}'
f"?charset={DB_CHARSET}")
engine = create_engine(
connection_string,
connect_args=connect_args,
)
app = Flask(__name__)
@app.route('/')
def mainpage():
return render_template('base.html')
@app.route('/patients')
def patients():
# Establish a database connection
with engine.connect() as connection:
# Execute an SQL query to fetch data (replace this with your query)
query1 = text('SELECT * FROM patients')
result1 = connection.execute(query1)
# Fetch all rows of data
db_data1 = result1.fetchall()
return render_template('patients.html', data1=db_data1)
@app.route('/laboratorytest')
def laboratory_test():
# Establish a database connection
with engine.connect() as connection:
# Execute an SQL query to fetch data (replace this with your query)
query2 = text('SELECT * FROM laboratory_test')
result2 = connection.execute(query2)
# Fetch all rows of data
db_data2 = result2.fetchall()
return render_template('laboratorytest.html', data2=db_data2)
if __name__ == '__main__':
app.run(debug=True)