CLASS -12 TH








..........................................................



...........................................................











                
         Last Date  5th December 2023
          








Computer Networks
.......................................





...................................................................................





CS SYNOPSIS



Practicals
.................................................................................
 

Dear Students,
 Practical Experiments 17 to 19

     
   
Experiment -17
___________________
Date of Experiment:-



Q->Write a program to Fetch Hospital and Doctor Information using hospital Id and doctor Id.

Coding
________
import mysql.connector

def get_connection():
connection = mysql.connector.connect(host='localhost',
database='python_db',
user='root',
password='',charset='utf8')
return connection

def close_connection(connection):
if connection:
connection.close()

def get_hospital_detail(hospital_id):
try:
connection = get_connection()
cursor = connection.cursor()
select_query = """select * from Hospital where Hospital_Id = %s"""
cursor.execute(select_query, (hospital_id,))
records = cursor.fetchall()
print("Printing Hospital record")
for row in records:
print("Hospital Id:", row[0], )
print("Hospital Name:", row[1])
print("Bed Count:", row[2])
close_connection(connection)
except (Exception, mysql.connector.Error) as error:
print("Error while getting data", error)

def get_doctor_detail(doctor_id):
try:
connection = get_connection()
cursor = connection.cursor()
select_query = """select * from Doctor where Doctor_Id = %s"""
cursor.execute(select_query, (doctor_id,))
records = cursor.fetchall()
print("Printing Doctor record")
for row in records:
print("Doctor Id:", row[0])
print("Doctor Name:", row[1])
print("Hospital Id:", row[2])
print("Joining Date:", row[3])
print("Specialty:", row[4])
print("Salary:", row[5])
print("Experience:", row[6])
close_connection(connection)
except (Exception, mysql.connector.Error) as error:
print("Error while getting data", error)

print(" Read given hospital and doctor details \n")
hos_id=int(input("Enter hospital id:-\n"))
get_hospital_detail(hos_id)
print("\n")
doc_id=int(input("Enter Doctor id:-\n"))
get_doctor_detail(doc_id)

Output
________
Read given hospital and doctor details


Enter hospital id:-4

Printing Hospital record

Hospital Id: 4
Hospital Name: UCLA Medical Center
Bed Count: 1500



Enter Doctor id:-102

Printing Doctor record

Doctor Id: 102
Doctor Name: Michael
Hospital Id: 1
Joining Date: 2018-07-23
Specialty: Oncologist
Salary: 20000
Experience: None


Experiment-18

________________
Q->Write a program to get the list Of doctors as per the given specialty and salary.

Coding
________

import mysql.connector

def get_connection():
connection = mysql.connector.connect(host='localhost',
database='python_db',
user='root',
password='',charset='utf8')
return connection

def close_connection(connection):
if connection:
connection.close()

def get_specialist_doctors_list(speciality, salary):
try:
connection = get_connection()
cursor = connection.cursor()
sql_select_query = """select * from Doctor where Speciality=%s and Salary > %s"""
cursor.execute(sql_select_query, (speciality, salary))
records = cursor.fetchall()
print("Printing doctors whose specialty is", speciality, "and salary greater than", salary, "\n")
for row in records:
print("Doctor Id: ", row[0])
print("Doctor Name:", row[1])
print("Hospital Id:", row[2])
print("Joining Date:", row[3])
print("Specialty:", row[4])
print("Salary:", row[5])
print("Experience:", row[6], "\n")
close_connection(connection)
except (Exception, mysql.connector.Error) as error:
print("Error while getting data", error)

print(" Get Doctors as per given Speciality\n")
get_specialist_doctors_list("Garnacologist", 30000)


Output
_______________________
Get Doctors as per given Speciality

Printing doctors whose specialty is Garnacologist and salary greater than 30000

Doctor Id: 105
Doctor Name: Linda
Hospital Id: 3
Joining Date: 2004-06-04
Specialty: Garnacologist
Salary: 42000
Experience: None

Doctor Id: 107
Doctor Name: Richard
Hospital Id: 4
Joining Date: 2014-08-21
Specialty: Garnacologist
Salary: 32000
Experience: None


Experiment-19


Q->Write a program to update doctor's experience in years.

Coding
________________
import mysql.connector
import datetime
from dateutil.relativedelta import relativedelta

def get_connection():
connection = mysql.connector.connect(host='localhost',
database='python_db',
user='root',
password='',charset='utf8')
return connection

def close_connection(connection):
if connection:
connection.close()

def update_doctor_experience(doctor_id):
# Update Doctor Experience in Years
try:
# Get joining date
connection = get_connection()
cursor = connection.cursor()
select_query = """select Joining_Date from Doctor where Doctor_Id = %s"""
cursor.execute(select_query, (doctor_id,))
joining_date = cursor.fetchone()

# calculate Experience in years
joining_date_1 = datetime.datetime.strptime(''.join(map(str, joining_date)), '%Y-%m-%d')
today_date = datetime.datetime.now()
experience = relativedelta(today_date, joining_date_1).years

# Update doctor's Experience now
connection = get_connection()
cursor = connection.cursor()
sql_select_query = """update Doctor set Experience = %s where Doctor_Id =%s"""
cursor.execute(sql_select_query, (experience, doctor_id))
connection.commit()
print("Doctor Id:", doctor_id, " Experience updated to ", experience, " years")
close_connection(connection)

except (Exception, mysql.connector.Error) as error:
print("Error while getting doctor's data", error)

print(" Calculate and Update experience of doctor according to id \n")
doc_id=int(input("Enter the doctor id:-"))
update_doctor_experience(doc_id)


Output
_________
Calculate and Update experience of doctor according to id


Enter the doctor id:-104
Doctor Id: 104 Experience updated to 2 years








Thank you.

Comments

  1. Sir you said that you will upload the details of boards CSpractical.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete

Post a Comment

Popular posts from this blog