Skip to main content

A Disease Detecting Program in python With mysql Databases.


import time
 import mysql.connector
from mysql.connector import errorcode
import datetime
from datetime import datetime
print("To make connection with your pc's mysql please enter your mysql information:")
user=input("Enter your computer's username:")
pass_=input("Enter your computer's passward:")
con=mysql.connector.connect(host='localhost',user=user ,password=pass_ )
if con.is_connected():
    print("Welcome To Disease Detection")
cur=con.cursor()

def create_db():
    while True:
        try:
            cur.execute("create database hospital")
            con.commit()
            break
        except mysql.connector.Error:
            time.sleep(1)
            return False
create_db()
while (False):
    if create_db():
        break
    elsecontinue
print("Database Created Sucessfully.....")
con=mysql.connector.connect(host='localhost',user=user ,password=pass_ ,database='hospital')
cur=con.cursor()

def create_t_users():
    while True:
        try:
            cur.execute("create table users( user_name varchar(25) NOT NULL PRIMARY KEY , user_password varchar(16) )")
            con.commit()
            break
        except mysql.connector.Error:
            time.sleep(1)
            return False
while (False):
    if create_t_users():
        break
    elsecontinue
create_t_users()
print("Table Created Sucessfully.......")

def symptoms_db():
    while True:
        try:
            cur.execute("create table symptoms( symptoms varchar(16) , S_ID varchar(16))")
            query2="""insert into symptoms values( 'fever' , '2 3 4 5'),( 'COVID 19' , '3 14 6 7'),( 'Maleria' , '2 8 3 6'),
            ( 'Dengue' , '3 8 10 14'),( 'Typhoid' , '9 3 6 2'),( 'Diabeties' , '11 8 12 13'),('Cancer','8 12 2 7'),
            ( 'Liver Disease' , '11 8 12 13'),( 'Heart Disease' , '7 1 5 15'),( 'Asthamatic' , '2 7 14 5')""" 
            query6="create table users_data( user_name varchar(16) , Disease varchar(16) ,date datetime)"                   
            cur.execute(query2)
            cur.execute(query6)
            con.commit()
            break
        except mysql.connector.Error:
            time.sleep(.1)
            return False
while (False):
    if symptoms_db():
        break
    elsecontinue
symptoms_db()
time.sleep(.5)
print("Tables are up to date:")
time.sleep(1)

def Sign_IN():
    print("-:Sign_UP Please:-")
    u_n=input("Enter your Name please:")
    u_p1=input("Create a password:")
    u_p2=input("Re-enter your password:")
    if u_p1==u_p2:
        def insert():
            while True:
                try:
                    query1="insert into users(user_name, user_password) values('{}','{}')".format(u_n,u_p1)
                    cur.execute(query1)
                    con.commit()
                    print("Sucessfully Sign_UP")
                    break
                except mysql.connector.Error:
                    print("username already exists please choose another username:-")
                    time.sleep(1)
                    return False
        insert()
        while (False):
            if insert():
                break
            elsecontinue
    else:
        print("password not matching")


def Log_IN():
    time.sleep(1)
    print("-:Log_IN in plaese:-")
    u_n1=input("Enter your Name please:")
    u_p4=input("Create your password:")
    sql_select_Query = "select * from users"
    cur=con.cursor()
    cur.execute(sql_select_Query)
    data=cur.fetchall()
    for rec in data:
        if (u_n1==rec[0]) and (u_p4==rec[1]):
            time.sleep(.5)
            print("-:Sucessfully Login:- ")
            f=int(input("Enter 1 to Start the test:\nEnter 2 to fetch your Previous details:\nEnter 3 to exit:"))
            def test():
                q1=input("Slowheartbeat.(y/n):" )+ ' 1'
                q2=input("Chills and shivering(y/n):")+ ' 2'
                q3=input("Headache(y/n):")+ ' 3'
                q4=input("Loss of apetite (y/n):")+ ' 4'
                q5=input("Weakness (y/n):")+ ' 5'
                q6=input("Diarrihoea(y/n):",)+ ' 6'
                q7=input("Trouble in breathing(y/n):")+ ' 7'
                q8=input("Fatique (y/n):")+ ' 8'
                q9=input("Stomach pain(y/n):")+ ' 9'
                q10=input("Low platelets(y/n):")+ ' 10'
                q11=input("Hunger(y/n):")+ ' 11'
                q12=input("Wheight changes(y/n):")+ ' 12'
                q13=input("Increased Thrust(y/n):")+ ' 13'
                q14=input("Pain or Ache(y/n):")+ ' 14'
                q15=input("Swelling In Legs(y/n):")+ ' 15'
                q16=input("Sweating (y/n):")+ ' 16'
                Fever=Covid_19=Maleria=Dengue=Typhoid=Diabeties=Cancer=Liver_disease=Heart_disease=Asthamatic=0
                l3=[q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,q13,q14,q15,q16]
                for i in l3:
                    for k in range(0,4):
                        if i[0]=='y':
                            p=i.split()
                            cur.execute("SELECT * FROM symptoms LIMIT 1 OFFSET 0")
                            row=cur.fetchmany()
                            for result in row:
                                l1=result[1]
                                e=l1.split()
                                if p[1]==e[k]:
                                    Fever+=1
                            cur.execute("SELECT * FROM symptoms LIMIT 1 OFFSET 1")
                            row=cur.fetchmany()
                            for result in row:
                                l1=result[1]
                                e=l1.split()
                                if p[1]==e[k]:
                                    Covid_19+=1
                            cur.execute("SELECT * FROM symptoms LIMIT 1 OFFSET 2")
                            row=cur.fetchmany()
                            for result in row:
                                l1=result[1]
                                e=l1.split()
                                if p[1]==e[k]:
                                    Maleria+=1
                            cur.execute("SELECT * FROM symptoms LIMIT 1 OFFSET 3")
                            row=cur.fetchmany()
                            for result in row:
                                l1=result[1]
                                e=l1.split()
                                if p[1]==e[k]:
                                    Dengue+=1
                            cur.execute("SELECT * FROM symptoms LIMIT 1 OFFSET 4")
                            row=cur.fetchmany()
                            for result in row:
                                l1=result[1]
                                e=l1.split()
                                if p[1]==e[k]:
                                    Typhoid+=1
                            cur.execute("SELECT * FROM symptoms LIMIT 1 OFFSET 5")
                            row=cur.fetchmany()
                            for result in row:
                                l1=result[1]
                                e=l1.split()
                                if p[1]==e[k]:
                                    Diabeties+=1
                            cur.execute("SELECT * FROM symptoms LIMIT 1 OFFSET 6")
                            row=cur.fetchmany()
                            for result in row:
                                l1=result[1]
                                e=l1.split()
                                if p[1]==e[k]:
                                    Cancer+=1      
                            cur.execute("SELECT * FROM symptoms LIMIT 1 OFFSET 7")
                            row=cur.fetchmany()
                            for result in row:
                                l1=result[1]
                                e=l1.split()
                                if p[1]==e[k]:
                                    Liver_disease+=1
                            cur.execute("SELECT * FROM symptoms LIMIT 1 OFFSET 8")
                            row=cur.fetchmany()
                            for result in row:
                                l1=result[1]
                                e=l1.split()
                                if p[1]==e[k]:
                                    Heart_disease+=1
                            cur.execute("SELECT * FROM symptoms LIMIT 1 OFFSET 9")
                            row=cur.fetchmany()
                            for result in row:
                                l1=result[1]
                                e=l1.split()
                                if p[1]==e[k]:
                                    Asthamatic+=1   
                Fever,Covid_19,Maleria=str(Fever)+' Fever',str(Covid_19)+' Covid_19',str(Maleria)+ ' Maleria'
                Diabeties,Dengue,Typhoid=str(Diabeties)+' Diabeties',str(Dengue)+' Dengue',str(Typhoid)+' Typhoid'
                Cancer,Liver_disease=str(Cancer)+' Cancer',str(Liver_disease)+' Liver_disease'
                Heart_disease,Asthamatic=str(Heart_disease)+' Heart_disease',str(Asthamatic)+' Asthamatic'
                b=max(Fever,Covid_19,Maleria,Dengue,Typhoid,Diabeties,Cancer,Liver_disease,Heart_disease,Asthamatic)            
                b=b.split()
                print(b[1])
                query7="insert into users_data values('{}','{}',now())".format(u_n1,b[1])
                cur.execute(query7)
                con.commit()
            def fetch_db():
                query8="select * from users_data where user_name='{}'".format(u_n1)
                cur.execute(query8)
                data1=cur.fetchall()
                for l in data1:
                    print(l)
            if f==1:    
                test()
                break
            elif f==2:
                fetch_db()
                break
            elif f==3:
                break
            elseprint("Incorrect input")
        else:
            print("Login failed")    

def first_p():
    while True:
        q=int(input("Enter 1 to Log IN \nEnter 2 to Sign IN\nEnter 3 to exit:"))
        if (q==1):
            Log_IN()
        elif (q==2):
            Sign_IN()
        elif (q==3):
            break
        else :
            print("Enter correct NO:")
first_p()        
print("Plese take care of your health...........")

con.close()

Comments

Popular posts from this blog

Write a C Program to Demonstrate the Working of Keyword long.

 #include<stdio.h> //24. Write a C Program to Demonstrate the Working of Keyword long. void main() {     int a;     long b;     long long c;     double e;     long double f;     printf(" The size of int = %ld bytes \n", sizeof(a));     printf(" The size of long = %ld bytes\n", sizeof(b));     printf(" The size of long long = %ld bytes\n", sizeof(c));     printf(" The size of double = %ld bytes\n", sizeof(e));     printf(" The size of long double = %ld bytes\n\n", sizeof(f)); }

A Program To Guessing A Number.

n=18 number_of_guesses=1 print ( "Number of guesses is limited to only 9 times: " ) while (number_of_guesses<=9):     guess_number = int ( input ( "Guess the number :\n" ))     if guess_number<18:         print ( "you enter less number please input greater number.\n" )     elif guess_number>18:         print ( "you enter greater number please input smaller number.\n " )     else :         print ( "you won\n" )         print (number_of_guesses, "no.of guesses he took to finish." )         break     print (9-number_of_guesses, "no. of guesses left" )     number_of_guesses = number_of_guesses + 1 if (number_of_guesses>9):     print ( "Game Over" )