0% found this document useful (0 votes)
15 views3 pages

Python Project

The document contains a Python script that connects to a MySQL database to manage patient records in a medical treatment management system. It includes functions for adding, displaying, editing, and deleting patient records, as well as user account creation and login. The script utilizes a command-line interface for user interaction and database operations.

Uploaded by

poorneshwar2908
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Python Project

The document contains a Python script that connects to a MySQL database to manage patient records in a medical treatment management system. It includes functions for adding, displaying, editing, and deleting patient records, as well as user account creation and login. The script utilizes a command-line interface for user interaction and database operations.

Uploaded by

poorneshwar2908
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import mysql.

connector as m
mydb = [Link](host = 'localhost', user = 'root', password = '0000')
cursor = [Link]()
[Link]('create database if not exists log' )
[Link]('use log')
[Link]('create table if not exists users(username varchar(20),
password varchar(20))')
[Link]('create table if not exists patient(p_id int, pname
varchar(20), treatment varchar(20), dname varchar(20))')
[Link]() # to save changes

def delete_record(user):
p_id = int(input("Enter patient id : "))

# to check the pid no availability in db


[Link]('select * from patient')
res = [Link]()
found = False
for row in res:
if row[0] == p_id:
found = True
#delete from patient where p_id = 'pid'
q = 'delete from patient where p_id = ' + str( p_id)
#print(q)
[Link](q)
[Link]()
print("Patient id ", p_id, "deleted successfully")
if found == False:
print("Patient id ", p_id, "not found")

second_level_menu(user)

def edit_record(user):
p_id = input("Enter patient id : ")
treatment = input("Enter new treatment details : ")
# to edit the record
q = 'update patient set treatment = " ' + str(treatment) + '" where
p_id = ' + str(p_id)
#print(q)
[Link](q)
[Link]()
print("Patient id ", p_id, "edited successfully")
second_level_menu(user)

def display_record(user):
[Link]('select * from patient')
res = [Link]()
print(" Patient ID Patient Name Treatment Dr
Name")
for patient in res:
if int(len(patient[2])) > 8:
print('\t', patient[0], '\t',patient[1], '\t',patient[2],
'\t',patient[3])
else:
print('\t', patient[0], '\t',patient[1], '\t',patient[2],
'\t','\t','\t',patient[3])
print()
second_level_menu(user)

def add_record(user):
p_id = input("Enter patient id : ")
pname = input("Enter patient name : ")
treatment = input("Enter treatment details : ")
dname = input("Enter consultant doctor : ")
q = 'insert into patient values (' + str(p_id) + ',"' + str(pname)
+ '","' + str(treatment) + '","' + str(dname) + '")'
#print(q)
[Link](q)
[Link]()
print("Patient inserted successfully")
second_level_menu(user)

def second_level_menu(user):
print()
print('Welcome ', user)
print('''
_________________________________________
Medical Treatment Management System
_________________________________________

1. Add patient record


2. Display patient record
3. Edit patient record
4. Delete patient record
5. Logout
''')
print()

choice = input("Enter your choice : ")

if choice == "1":
add_record(user)
elif choice == '2':
display_record(user)
elif choice == '3':
edit_record(user)
elif choice == '4':
delete_record(user)
elif choice == '5':
print('You have logged out successfully')

def log_in():
username = input("Enter username: ")

# to fetch records from db


[Link]('select * from users')
result = [Link]()
found = False
for user in result:
if user[0] == username:
found = True
pwd = input("Enter password: ")
if user[1] == pwd:
second_level_menu(user[0])
else:
print('Password invalid')
if found == False:
print('User not found')

def create():
username = input("Enter username: ")
pwd = input("Enter password: ")
q = 'insert into users values("' + str(username) +'","' + str(pwd)
+ '")'
print(q)
[Link](q)
[Link]()
print('User account created successfully')

while True:
print('First level menu')
print(" 1. Create account")
print(" 2. Log in")
print(" 3. Exit")

choice = input("Enter your choice : ")

if choice == "1":
create()
elif choice =='2':
log_in()

You might also like