Pranay25 commited on
Commit
5b7e864
·
verified ·
1 Parent(s): 34aa274

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -112
app.py CHANGED
@@ -1,113 +1,72 @@
1
  # app.py
2
- from flask import Flask, render_template, request, redirect, url_for, flash
3
- import sqlite3
4
- from datetime import datetime
5
-
6
- app = Flask(__name__)
7
- app.secret_key = 'supersecretkey'
8
-
9
- # Database connection helper
10
- def get_db_connection():
11
- conn = sqlite3.connect('healthcare.db')
12
- conn.row_factory = sqlite3.Row
13
- return conn
14
-
15
- ### 1. Patient Registration ###
16
- @app.route('/register', methods=['GET', 'POST'])
17
- def register():
18
- if request.method == 'POST':
19
- name = request.form['name']
20
- age = request.form['age']
21
- gender = request.form['gender']
22
- mobile = request.form['mobile']
23
-
24
- if len(mobile) != 10 or not mobile.isdigit():
25
- flash("Mobile number must be exactly 10 digits.", "error")
26
- return redirect(url_for('register'))
27
-
28
- conn = get_db_connection()
29
- conn.execute("INSERT INTO patients (name, age, gender, mobile) VALUES (?, ?, ?, ?)",
30
- (name, age, gender, mobile))
31
- conn.commit()
32
- patient_id = conn.execute("SELECT last_insert_rowid()").fetchone()[0]
33
- conn.close()
34
-
35
- flash(f'Registration successful! Patient ID: {patient_id}', 'success')
36
- return redirect(url_for('register'))
37
-
38
- return render_template('register.html')
39
-
40
- ### 2. Book Appointment ###
41
- @app.route('/book', methods=['GET', 'POST'])
42
- def book():
43
- conn = get_db_connection()
44
- doctors = ["Dr. Pranay - Cardiology", "Dr. Priyanka - Gynecology", "Dr. Pavan - Physiotherapy",
45
- "Dr. Pranav - Orthopedic", "Dr. Uday - General Surgery", "Dr. RajaSuri - Psychology"]
46
- if request.method == 'POST':
47
- patient_id = request.form['patient_id']
48
- doctor = request.form['doctor']
49
- date = request.form['date']
50
- time_slot = request.form['time_slot']
51
-
52
- # Check if slot is available
53
- slot_check = conn.execute(
54
- "SELECT * FROM appointments WHERE date = ? AND time_slot = ? AND doctor = ?",
55
- (date, time_slot, doctor)).fetchone()
56
- if slot_check:
57
- flash("Slot is already booked. Please choose another.", "error")
58
- else:
59
- conn.execute("INSERT INTO appointments (patient_id, doctor, date, time_slot, is_booked) VALUES (?, ?, ?, ?, ?)",
60
- (patient_id, doctor, date, time_slot, 1))
61
- conn.commit()
62
- flash("Appointment booked successfully!", "success")
63
-
64
- conn.close()
65
- return redirect(url_for('book'))
66
-
67
- return render_template('book.html', doctors=doctors)
68
-
69
- ### 3. Laboratory Tests ###
70
- @app.route('/lab', methods=['GET', 'POST'])
71
- def lab():
72
- tests = {"Urine Test": 200, "Blood Test": 500, "CBP": 300, "Saliva Test": 150}
73
- if request.method == 'POST':
74
- patient_id = request.form['patient_id']
75
- selected_tests = request.form.getlist('tests')
76
- conn = get_db_connection()
77
-
78
- total_amount = 0
79
- for test in selected_tests:
80
- amount = tests[test]
81
- total_amount += amount
82
- conn.execute("INSERT INTO lab_tests (patient_id, test_name, amount) VALUES (?, ?, ?)",
83
- (patient_id, test, amount))
84
-
85
- # Link total amount to billing
86
- conn.execute("INSERT INTO billing (patient_id, total_amount) VALUES (?, ?)",
87
- (patient_id, total_amount))
88
- conn.commit()
89
- conn.close()
90
- flash(f"Lab tests booked successfully! Total amount: {total_amount}", "success")
91
-
92
- return redirect(url_for('lab'))
93
-
94
- return render_template('lab.html', tests=tests)
95
-
96
- ### 4. Reports ###
97
- @app.route('/reports/<int:patient_id>')
98
- def reports(patient_id):
99
- conn = get_db_connection()
100
- reports = conn.execute("SELECT * FROM lab_tests WHERE patient_id = ?", (patient_id,)).fetchall()
101
- conn.close()
102
- return render_template('reports.html', reports=reports)
103
-
104
- ### 5. Billing ###
105
- @app.route('/billing/<int:patient_id>')
106
- def billing(patient_id):
107
- conn = get_db_connection()
108
- billing = conn.execute("SELECT total_amount FROM billing WHERE patient_id = ?", (patient_id,)).fetchone()
109
- conn.close()
110
- return render_template('billing.html', billing=billing, patient_id=patient_id)
111
-
112
- if __name__ == "__main__":
113
- app.run(debug=True)
 
1
  # app.py
2
+ import gradio as gr
3
+ from patient_registration import register_patient
4
+ from appointment_booking import book_appointment
5
+ from laboratory import book_lab_tests
6
+ from reports import get_reports
7
+ from billing import get_billing
8
+
9
+ def register_interface(name, age, gender, mobile):
10
+ return register_patient(name, age, gender, mobile)
11
+
12
+ def book_interface(patient_id, doctor, date, time_slot):
13
+ return book_appointment(patient_id, doctor, date, time_slot)
14
+
15
+ def lab_interface(patient_id, tests):
16
+ return book_lab_tests(patient_id, tests)
17
+
18
+ def report_interface(patient_id):
19
+ return get_reports(patient_id)
20
+
21
+ def billing_interface(patient_id):
22
+ return get_billing(patient_id)
23
+
24
+ # Define Gradio app interfaces
25
+ with gr.Blocks() as app:
26
+ gr.Markdown("# Healthcare App")
27
+
28
+ # Patient Registration
29
+ with gr.Tab("Register Patient"):
30
+ name = gr.Textbox(label="Name")
31
+ age = gr.Number(label="Age")
32
+ gender = gr.Dropdown(["Male", "Female", "Other"], label="Gender")
33
+ mobile = gr.Textbox(label="Mobile Number")
34
+ register_btn = gr.Button("Register")
35
+ register_output = gr.Textbox()
36
+ register_btn.click(register_interface, inputs=[name, age, gender, mobile], outputs=register_output)
37
+
38
+ # Book Appointment
39
+ with gr.Tab("Book Appointment"):
40
+ patient_id = gr.Number(label="Patient ID")
41
+ doctor = gr.Dropdown(["Dr. Pranay - Cardiology", "Dr. Priyanka - Gynecology", "Dr. Pavan - Physiotherapy",
42
+ "Dr. Pranav - Orthopedic", "Dr. Uday - General Surgery", "Dr. RajaSuri - Psychology"], label="Doctor")
43
+ date = gr.Textbox(label="Date (YYYY-MM-DD)")
44
+ time_slot = gr.Textbox(label="Time Slot (e.g., 9 AM - 10 AM)")
45
+ book_btn = gr.Button("Book Appointment")
46
+ book_output = gr.Textbox()
47
+ book_btn.click(book_interface, inputs=[patient_id, doctor, date, time_slot], outputs=book_output)
48
+
49
+ # Laboratory Tests
50
+ with gr.Tab("Laboratory Tests"):
51
+ patient_id_lab = gr.Number(label="Patient ID")
52
+ tests = gr.CheckboxGroup(["Urine Test", "Blood Test", "CBP", "Saliva Test"], label="Select Tests")
53
+ lab_btn = gr.Button("Book Tests")
54
+ lab_output = gr.Textbox()
55
+ lab_btn.click(lab_interface, inputs=[patient_id_lab, tests], outputs=lab_output)
56
+
57
+ # Reports
58
+ with gr.Tab("Reports"):
59
+ patient_id_reports = gr.Number(label="Patient ID")
60
+ report_btn = gr.Button("Get Reports")
61
+ report_output = gr.Textbox()
62
+ report_btn.click(report_interface, inputs=[patient_id_reports], outputs=report_output)
63
+
64
+ # Billing
65
+ with gr.Tab("Billing"):
66
+ patient_id_billing = gr.Number(label="Patient ID")
67
+ billing_btn = gr.Button("Get Billing")
68
+ billing_output = gr.Textbox()
69
+ billing_btn.click(billing_interface, inputs=patient_id_billing, outputs=billing_output)
70
+
71
+ # Launch the app
72
+ app.launch()