Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
from tkinter import messagebox
class Patient:
def __init__(self, id, name, test, payment, advice):
self.id = id
self.name = name
self.test = test
self.payment = payment
self.advice = advice
def get_discount(self, percentage):
self.payment -= self.payment * percentage / 100
def display(self):
return f"nId: {self.id}nName: {self.name}nTest: {self.test}nPayment: {self.payment}nAdvice: {self.advice}n"
class PatientManagement:
def __init__(self):
self.patients = []
def add_patient(self, id, name, test, payment, advice):
patient = Patient(id, name, test, payment, advice)
self.patients.append(patient)
return "Patient detail added"
def apply_discount(self, patient_id, percentage):
patient = self.find_patient_by_id(patient_id)
if patient:
patient.get_discount(percentage)
return "Discount added"
else:
return "Patient not found"
def display_patient(self, patient_id):
patient = self.find_patient_by_id(patient_id)
if patient:
return patient.display()
else:
return "Patient not found"
def find_patient_by_id(self, patient_id):
for patient in self.patients:
if patient.id == patient_id:
return patient
return None
class GUI(tk.Tk):
def __init__(self):
super().__init__()
self.title("Patient Management System")
self.patient_management = PatientManagement()
self.create_widgets()
def create_widgets(self):
tk.Label(self, text="Choose:", font=("Helvetica", 16, "bold"), pady=10).grid(row=0, column=0, columnspan=2)
buttons = [
("Input Patient Detail", self.input_patient_detail),
("Get Discount", self.get_discount),
("Show Patient Detail", self.show_patient_detail),
("Exit", self.exit_program)
]
row_num = 1
for text, command in buttons:
tk.Button(self, text=text, command=command, width=20, height=2, font=("Helvetica", 12)).grid(row=row_num, column=0, columnspan=2, pady=5)
row_num += 1
def input_patient_detail(self):
input_window = tk.Toplevel(self)
input_window.title("Input Patient Detail")
tk.Label(input_window, text="Patient's Id:", font=("Helvetica", 12)).grid(row=0, column=0, padx=10, pady=10)
id_entry = tk.Entry(input_window, font=("Helvetica", 12))
id_entry.grid(row=0, column=1, padx=10, pady=10)
tk.Label(input_window, text="Patient's Name:", font=("Helvetica", 12)).grid(row=1, column=0, padx=10, pady=10)
name_entry = tk.Entry(input_window, font=("Helvetica", 12))
name_entry.grid(row=1, column=1, padx=10, pady=10)
tk.Label(input_window, text="Test Name:", font=("Helvetica", 12)).grid(row=2, column=0, padx=10, pady=10)
test_entry = tk.Entry(input_window, font=("Helvetica", 12))
test_entry.grid(row=2, column=1, padx=10, pady=10)
tk.Label(input_window, text="Payment:", font=("Helvetica", 12)).grid(row=3, column=0, padx=10, pady=10)
payment_entry = tk.Entry(input_window, font=("Helvetica", 12))
payment_entry.grid(row=3, column=1, padx=10, pady=10)
tk.Label(input_window, text="Advice:", font=("Helvetica", 12)).grid(row=4, column=0, padx=10, pady=10)
advice_entry = tk.Entry(input_window, font=("Helvetica", 12))
advice_entry.grid(row=4, column=1, padx=10, pady=10)
submit_button = tk.Button(input_window, text="Submit", command=lambda: self.submit_patient_detail(id_entry.get(), name_entry.get(), test_entry.get(), payment_entry.get(), advice_entry.get(), input_window), width=15, height=2, font=("Helvetica", 12))
submit_button.grid(row=5, column=0, columnspan=2, pady=10)
def submit_patient_detail(self, id, name, test, payment, advice, window):
try:
id = int(id)
payment = float(payment)
result = self.patient_management.add_patient(id, name, test, payment, advice)
messagebox.showinfo("Success", result)
window.destroy()
except ValueError:
messagebox.showerror("Error", "Invalid input. Please enter valid values.")
def get_discount(self):
if self.patient_management.patients:
discount_window = tk.Toplevel(self)
discount_window.title("Apply Discount")
tk.Label(discount_window, text="Patient's Id:", font=("Helvetica", 12)).grid(row=0, column=0, padx=10, pady=10)
id_entry = tk.Entry(discount_window, font=("Helvetica", 12))
id_entry.grid(row=0, column=1, padx=10, pady=10)
tk.Label(discount_window, text="Discount Percentage:", font=("Helvetica", 12)).grid(row=1, column=0, padx=10, pady=10)
percentage_entry = tk.Entry(discount_window, font=("Helvetica", 12))
percentage_entry.grid(row=1, column=1, padx=10, pady=10)
submit_button = tk.Button(discount_window, text="Apply Discount", command=lambda: self.apply_discount(id_entry.get(), percentage_entry.get(), discount_window), width=15, height=2, font=("Helvetica", 12))
submit_button.grid(row=2, column=0, columnspan=2, pady=10)
else:
messagebox.showwarning("Warning", "No patient details found. Enter patient detail first")
def apply_discount(self, patient_id, percentage, window):
try:
patient_id = int(patient_id)
percentage = float(percentage)
result = self.patient_management.apply_discount(patient_id, percentage)
messagebox.showinfo("Success", result)
window.destroy()
except ValueError:
messagebox.showerror("Error", "Invalid input. Please enter valid values.")
def show_patient_detail(self):
if self.patient_management.patients:
show_detail_window = tk.Toplevel(self)
show_detail_window.title("Show Patient Detail")
tk.Label(show_detail_window, text="Patient's Id:", font=("Helvetica", 12)).grid(row=0, column=0, padx=10, pady=10)
id_entry = tk.Entry(show_detail_window, font=("Helvetica", 12))
id_entry.grid(row=0, column=1, padx=10, pady=10)
submit_button = tk.Button(show_detail_window, text="Show Detail", command=lambda: self.display_patient_detail(id_entry.get(), show_detail_window), width=15, height=2, font=("Helvetica", 12))
submit_button.grid(row=1, column=0, columnspan=2, pady=10)
else:
messagebox.showwarning("Warning", "No patient details found. Enter patient detail first")
def display_patient_detail(self, patient_id, window):
try:
patient_id = int(patient_id)
result = self.patient_management.display_patient(patient_id)
messagebox.showinfo("Patient Detail", result)
window.destroy()
except ValueError:
messagebox.showerror("Error", "Invalid input. Please enter a valid patient ID.")
def exit_program(self):
if messagebox.askokcancel("Exit", "Are you sure you want to exit?"):
print("Exiting the program")
self.destroy()
if __name__ == "__main__":
app = GUI()
app.mainloop()
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team