1. 题目意义

医院信息管理是一项琐碎、复杂而又十分细致的工作,这关系到医院体系能否运行起来这一关乎国民健康水平的重大问题。我们只有利用好了医院中每个医生、护士的各项资源,才能使得医院系统能够有序而条理的进行,更好的安排有限的医生和护士资源,安排患者就诊。同时,在设计医院信息管理系统的同时也兼顾了药品的管理,使得我们在安排各项工作的时候能够更加的清晰明了,其可以与药房管理系统和挂号管理系统相连接,更好的实现医院的管理功能

2.数据输入功能

1>科室实体。包括科室编号,科室名称,科室地址,科室电话…

2>医生实体。包括医生编号,医生姓名,职务,性别,年龄…

3>病房实体。包括房间号,房间地址…

4>患者实体,包括患者编号,患者名,性别,年龄…

5>护士实体。包括护士编号,护士姓名,性别,年龄…

6>药品实体。包括药品编号,药品名,供应商,库存,价格…

7>病房从属科室关系。

8>科室下属医生关系。

9>患者的主治医生关系。包括疾病…

10>护士护理患者关系。包括护理内容,时间…

11>患者入住病房关系。包括入住时间,预计出院时间…

12>患者使用药品关系。包括数量…

  1. 查询和统计功能:根据患者查询其主治医生和用药等,并对其花费进行统计。

2概念结构设计

根据需求分析结构,构建E-R图,如图2-1所示。

3逻辑结构设计

3.1关系模型设计

1.医生(医生编号,姓名,性别,年龄,职务,科室编号)

2.科室(科室编号,科室名称,科室地址,科室电话)

3.病房(病房编号,病房地址,所属部门号)

4.患者(患者编号,姓名,性别,年龄,疾病,主治医生编号,所住病号编号,住院时间,预计出院时间)

5.护士(护士编号,姓名,性别,年龄)

6.药品(药品编号,药品名称,药品厂家,药品库存,药品售价)

7.护理记录表(患者编号,护士编号,护理内容,护理时间)

8.用药记录表(患者编号,药品编号,用药数量)

4数据库的实现

4.1建表代码

1. 医生表的创建:

create table doctor
(
  dno char(3) primary key,
  dname char(20),
  duty char(20),
  dsex bit(1),
  dage int check (page>=0 and page <=150),
  dpno char(1),
  foreign key (dpno) references department(dpno)
);

插入数据:

insert into doctor values (“101″,”李小明”,”中级医师”,1,18,”1″);

2. 部门表的创建:

create table department
(
  dpname char(10) not null unique,
  dpno char(1) primary key,
  dpadr char(20),
  dptel char(20)
);

插入数据:

insert into department values(“内科”,”1″,”一号楼514″,”04512340987″);

3. 病房表的创建:

 create table room
 (
   rno char(10) primary key ,
   radr char(20) unique,
   dpno char(5),
  foreign key (dpno) references department(dpno)
 );

 插入数据:

insert into room values (“1101″,”一号楼101″,”1”),;

 

4. 患者表的创建:

create table patient
(
  pno char(20) primary key,
  pname char(20) not null,
  psex bit(1),
  page int check (page>=0 and page <=150),
  dno char(3),
  rno char(10),
  illness char(20),
  startdate date,
  predictenddate date,
  foreign key (dno) references doctor(dno),
  foreign key (rno) references room(rno)
);

插入数据:

insert into patient values 

 (“0001″,”赵一”,1,20,”101″,”1101″,”左脚踝粉碎性骨折”,”2018-12-20″,”2019-01-28″);

 

5. 护士表的创建:

create table nurse
(
  nno char(2) primary key ,
  nname char(10) unique ,
  nsex bit(1),
  nage int
);

插入数据:

insert into nurse values (“01″,”黎晓蓓”,0,21);

 

6. 药品表的创建:

create table drug
(
  dgno char(4) primary key ,
  dgname char(20),
  dgpro char(20),
  dgnum int check(dgnum>=0),
  dgprice int check(dgprice>=0)
);

插入数据:

insert into drug values  (“0001″,”注射用苄星青霉素”,”哈尔滨制药厂”,123,24);

 

7. 护理记录表的创建:

create table PN
(
  pno char(20),
  nno char(2),
  content char(20),
  time datetime,
  foreign key (pno) references patient(pno),
  foreign key (nno) references nurse(nno)
);

插入数据:

insert into PN values (“0001″,”01″,”康复治疗1″,”2018-12-22 13:12:11”);

 

8. 用药记录表的创建:

create table PD
(
  dgno char(4),
  pno char(4),
  num int check(num>=0),
  foreign key (dgno) references drug(dgno),
  foreign key (pno)  references patient(pno),
  primary key (dgno,pno)
);

插入数据:

insert into PD values     (“0001″,”0001”,1);

 

4.2数据操纵代码

数据控制部分采用Python连接MySQL数据库来操纵数据,其主要步骤为:

1. 增:

1>增加科室

sql = “INSERT INTO department (dpname, dpno, dpadr,dptel) VALUES (\’%s\’,\’%s\’,\’%s\’,\’%s\’ )”

输入科室的编号,地址,科室名称,科室电话进行匹配SQL语句。

2>增加医生

sql = “INSERT INTO doctor (dno, dname, duty,dsex,dage,dpno) VALUES (\’%s\’,\’%s\’,\’%s\’,%d,%d,\’%s\’ )”

输入医生的编号,姓名,性别,职务,年龄和所属部门编号进行匹配SQL语句。

3>增加病房

sql = “INSERT INTO room (rno, radr, dpno) VALUES (\’%s\’,\’%s\’,\’%s\’ )”

输入病房的编号,病房地址和所属部门编号进行匹配SQL语句。

4>增加患者

sql = “INSERT INTO patient(pno ,pname,psex, page, dno, rno,illness, startdate, predictenddate) VALUES (\’%s\’,\’%s\’,%d,%d,\’%s\’,\’%s\’,\’%s\’,\’%s\’,\’%s\’)”

输入患者的编号,姓名,性别,年龄疾病,主治医生编号,入住时间,预计出院时间和所属部门编号进行匹配SQL语句。

5>增加护士

sql = “INSERT INTO nurse (nno, nname,nsex,nage) VALUES (\’%s\’,\’%s\’,%d,%d)”

输入护士的编号,姓名,性别和年龄进行匹配SQL语句。

6>增加药品

sql = “INSERT INTO drug (dgno, dgname,dgpro,dgnum,dgprice) VALUES (\’%s\’,\’%s\’,\’%s\’,%d,%d)”

输入药品的编号,名称,产地,库存和价格进行匹配SQL语句。

7>增加用药记录

sql = “INSERT INTO PD (dgno, pno, num) VALUES (\’%s\’,\’%s\’,%d)”

输入药品的编号,患者的编号和用药数目进行匹配SQL语句。

8>增加护理记录

sql = “INSERT INTO PN (pno, nno, content, time) VALUES (\’%s\’,\’%s\’,\’%s\’,\’%s\’)”

输入患者编号,护士编号,护理内容,护理时间来进行匹配SQL语句。

 

2. 删:因为部门,医生及病房的删除过程比较复杂,故不予考虑。

1> 删除患者

输入患者编号,删除其护理记录,用药记录和患者记录。

sql = “DELETE FROM PN  WHERE pno = \’%s\'”

删除护理记录

sql = “DELETE FROM PD  WHERE pno = \’%s\’ “

删除用药记录

sql = “DELETE FROM patient  WHERE pno = \’%s\'”

删除患者记录

2> 删除护士

输入护士编号,删除其护理记录,和护士记录。

sql = “DELETE FROM PN  WHERE nno = \’%s\'” 

删除护理记录

sql = “DELETE FROM nurse  WHERE nno = \’%s\’ “

删除护士记录

3> 删除药品

输入药品编号,删除其用药记录和药品记录。

sql = “DELETE FROM PD  WHERE dgno = \’%s\'”

删除用药记录

sql = “DELETE FROM drug  WHERE dgno = \’%s\’ “

删除药品记录

4> 删除护理记录

输入护士编号和患者编号,删除护理记录。

sql = “DELETE FROM PN  WHERE pno = \’%s\’ and nno = \’%s\'”

5> 删除用药记录

输入药品编号和患者编号,删除用药记录。

sql = “DELETE FROM PD  WHERE pno = \’%s\’ and dgno = \’%s\'”

 

3. 改:

1> 修改药品库存

输入药品编号来修改药品库存。

sql = “UPDATE drug SET  dgnum = %d WHERE dgno = \’%s\’ “

  1. 修改药品售价

输入药品编号来修改药品售价。

sql = “UPDATE drug SET  dgprice = %d WHERE dgno = \’%s\’ “

  1. 修改患者使用药品数量

输入药品编号和患者编号来修改患者使用药品数量。

sql = “UPDATE PD SET  num = %d WHERE dgno = \’%s\’ and pno = \’%s\’ “

  1. 修改患者预计出院时间

输入患者编号来修改预计出院时间。

sql = “UPDATE patient SET predictenddate = \’%s\’ WHERE pno = \’%s\’ “

  1. 修改患者房间号码

输入患者编号来修改患者房间号码。

sql = “UPDATE patient SET rno = \’%s\’ WHERE pno = \’%s\’ “

 

4. 查:这里的查询都是用的存储过程写的,故在这里直接写存储过程及在MySQL环境下的call调用过程。

1> 查询医生姓名及部门

create  procedure sl_department(in ddno char(4))
begin
  select dname 医生姓名,dpname 科室名
    from department,doctor
      where department.dpno = doctor.dpno
        and doctor.dno = ddno;
end;
call sl_department(“302”);

2> 查询科室的每个患者及其主治医师

create procedure sl_department_patientname(in ddpno char(1))
  begin
    select pname 患者名,patient.pno 患者编号,dname 主治医师姓名,doctor.dno 主治医师编号
      from patient,doctor,department
        where patient.dno = doctor.dno
          and department.dpno = doctor.dpno
            and ddpno = department.dpno ;
  end;
call sl_department_patientname(“1”);

3> 查询科室就诊人数

create procedure sl_department_patientnum(in ddpno char(1))
  begin
    select count(*) 科室患者数from patient,doctor,department
        where patient.dno = doctor.dno
          and department.dpno = doctor.dpno
            and ddpno = department.dpno ;
  end;
call sl_department_patientnum(“2”);

4> 查询患者的主治医生及其职务科室

create procedure sl_doctor(in ppno char(4))
  begin
    select doctor.dname 医生姓名,doctor.duty 职务,dpname 科室名from doctor,department
        where department.dpno = doctor.dpno
          and dno in
              (select dno from patient
               where ppno = pno);
  end;
call sl_doctor(“0001”);

5> 查询医生主治的患者数量 

create procedure sl_doctor_patientnum(in ddno char(4))
  begin
    select count(*) 医生主治的患者数量from patient
      where patient.dno = ddno;
  end;
call sl_doctor_patientnum(“102”);

6> 查询患者用药情况

create procedure sl_drug_patient(in ppno char(4))
  begin
    select pname 患者姓名,illness 病症,dgname 药物名,num 数量
      from patient,drug,PD
        where patient.pno = pd.pno
          and drug.dgno = pd.dgno
            and pd.pno = ppno;
  end;
call sl_drug_patient(“0001”);

7> 查询患者应缴金额

create procedure sl_money(in ppno char(4))
  begin
    select sum(num * dgprice) 应缴金额
      from pd,patient,drug
        where pd.pno = patient.pno
          and drug.dgno = pd.dgno
            and patient.pno = ppno;
  end;
call sl_money(“0023”);

8> 查询科室的病房

create procedure sl_room(in ddpno char(1))
  begin
   select dpname 科室名,rno 病房编号,radr 病房地址
    from room,department
      where ddpno = room.dpno
       and room.dpno = department.dpno;
  end;
call sl_room(“1”);

9> 根据护士编号查询护士姓名

create procedure sl_nurse(in nnno char(2))
  begin
    select nno 护士编号,nname 护士姓名from nurse
        where nno = nnno;
  end;
call sl_nurse(“05”);

10> 查询患者进行护理的时间,内容及负责护士

create procedure sl_patient_nurse(in ppno char(4))
  begin
    select pname,illness,content,time,nname
    from nurse,patient,pn
        where nurse.nno = pn.nno
        and patient.pno = pn.pno
        and patient.pno = ppno;
  end;
call sl_patient_nurse(“0002”);

11> 以患者编号查询室友 

create procedure sl_patient_one_room(in ppno char(4))
  begin
    select A.pname,A.pno from patient A
        where rno in
              (select B.rno from patient B
              where B.pno=ppno);
  end;
call sl_patient_one_room(“0002”);

12> 查询同一病房的患者

create procedure sl_room_patient(in rrno char(4))
  begin
    select pno,pname from patient
        where rno = rrno;
  end;
call sl_room_patient(“1407”);

4.3用Python对数据进行操纵

1.增

向医生表中加入一个工号为104,姓名为李来文的医生,再查询是否增加了该条记录。

图4.13:增加界面

2.改

先查询1号患者所要支付的钱,再将药品价格上调后,查询1号患者所需支付的钱,不同则为修改了。

图4.14:修改界面

如上图:修改前为1883,修改后为1889,说明数据发生了修改。

 

3.删

先查询8号护士是否存在,看到存在后将其删了,再次查询看8号护士是否存在。

结果如下:

图4.15:删除界面

4.查

图4.16:查询界面

 

 

 

 

完整的python代码如下:

 

# coding=utf-8
"""
***********************help document****************************************
Usage:
    this is a simple hospital system,now is simple
    when start the programming,you can do following operations
    enter \'a\' is to insert data into database
    enter \'b\' is to display all data in database
    enter \'c\' is to query the specify info in database
    enter \'h\' is to see this help dacument
    enter \'d\' is to delete someone info
    enter nothing is to do nothing,you can enter again
    simple help document is: "a--insert/b--display/c--query/h--help/d--delete/\'\'--default"
    Also, you can use [enter] to end this program
Example:
    please enter the OPcode: a  then [enter]
*****************************************************************************

"""

#打印帮助文档
def help_document():
    print(__doc__)

import pymysql.cursors
import datetime
# 连接数据库

connect = pymysql.Connect(
host=\'localhost\',
port=3306,
user=\'root\',
passwd=\'12345678\',
db=\'hospital\',
charset=\'utf8\'
)
# 获取游标
cursor = connect.cursor()

# 实现switch-case语句
class switch(object):
    def __init__(self, value):
        self.value = value
        self.fall = False

    def __iter__(self):
        """Return the match method once, then stop"""
        yield self.match
        raise StopIteration

    def match(self, *args):
        """Indicate whether or not to enter a case suite"""
        if self.fall or not args:
            return True
        elif self.value in args:  # changed for v1.5, see below
            self.fall = True
            return True
        else:
            return False

def insert():
    # 插入数据
    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
    temp = input("输入你要插入的表格")
    while temp:
        for case in switch(temp):
            if case(\'1\'):
                try:
                    sql = "INSERT INTO department (dpname, dpno, dpadr,dptel) VALUES (\'%s\',\'%s\',\'%s\',\'%s\' )"
                    dpname = input("部门名称")
                    dpno   = input("部门编号")
                    dpno = (1-len(dpno))*\'0\'+dpno;
                    dpadr  = input("部门地址")
                    dptel  = input("部门电话")
                    data = (dpname, dpno, dpadr,dptel)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功插入\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                    temp = input("输入你要插入的表格")
                except:
                    print("存在约束条件,不能插入该数据!")
                    print()
                    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                    temp = input("输入你要插入的表格")
                break
            if case(\'2\'):
                try:
                    sql = "INSERT INTO doctor (dno, dname, duty,dsex,dage,dpno) VALUES (\'%s\',\'%s\',\'%s\',%d,%d,\'%s\' )"
                    dno = input("医生工号:")
                    dno = (3 - len(dno)) * \'0\' + dno;
                    dname = input("医生姓名:")
                    duty = input("职务:")
                    dsex = int(input("性别:"))
                    dage = int(input("年龄:"))
                    dpno = input("部门编号:")
                    data = (dno, dname, duty, dsex, dage, dpno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功插入\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                    temp = input("输入你要插入的表格")
                except:
                    print("存在约束条件,不能插入该数据!")
                    print()
                    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                    temp = input("输入你要插入的表格")
                break
            if case(\'3\'):
                try:
                    sql = "INSERT INTO room (rno, radr, dpno) VALUES (\'%s\',\'%s\',\'%s\' )"
                    rno = input("病房编号:")
                    rno = (4 - len(rno)) * \'0\' + rno;
                    radr   = input("病房地址")
                    dpno  = input("所属部门编号:")
                    dpno = (1 - len(dpno)) * \'0\' + dpno;
                    data = (rno, radr, dpno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功插入\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                    temp = input("输入你要插入的表格")
                except:
                    print("存在约束条件,不能插入该数据!")
                    print()
                    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                    temp = input("输入你要插入的表格")
                break
            if case(\'4\'):
                try:
                    sql = "INSERT INTO patient(pno ,pname,psex, page, dno, rno,illness, startdate, predictenddate) VALUES (\'%s\',\'%s\',%d,%d,\'%s\',\'%s\',\'%s\',\'%s\',\'%s\')"
                    pno = input("患者编号:")
                    pno = (4 - len(pno)) * \'0\' + pno;
                    pname = input("患者姓名:")
                    psex = int(input("性别:"))
                    page = int(input("年龄:"))
                    illness = input("疾病种类:")
                    dno = input("主治医师编号:")
                    dno = (4 - len(dno)) * \'0\' + dno;
                    rno = input("所住房间号:")
                    startdate = datetime.datetime.now().strftime("%Y-%m-%d")
                    print("输入预计出院时间")
                    nian = input("年:")
                    yue = input("月:")
                    ri = input("日:")
                    predictenddate = nian + "-" + yue + "-" + ri
                    data = (pno, pname, psex, page, dno, rno, illness, startdate, predictenddate)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功插入\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                    temp = input("输入你要插入的表格")
                except:
                    print("存在约束条件,不能插入该数据!")
                    print()
                    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                    temp = input("输入你要插入的表格")
                break
            if case(\'5\'):
                try:
                    sql = "INSERT INTO nurse (nno, nname,nsex,nage) VALUES (\'%s\',\'%s\',%d,%d)"
                    nno = input("护士工号:")
                    nno = (2 - len(nno)) * \'0\' + nno;
                    nname = input("护士姓名:")
                    nsex = int(input("性别:"))
                    nage = int(input("年龄:"))
                    data = (nno, nname,nsex,nage)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功插入\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                    temp = input("输入你要插入的表格")
                except:
                    print("存在约束条件,不能插入该数据!")
                    print()
                    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                    temp = input("输入你要插入的表格")
                break
            if case(\'6\'):
                try:
                    sql = "INSERT INTO drug (dgno, dgname,dgpro,dgnum,dgprice) VALUES (\'%s\',\'%s\',\'%s\',%d,%d)"
                    dgno = input("药品编号:")
                    dgno = (4-len(dgno))*\'0\'+dgno;
                    dgname = input("药品名称:")
                    dgpro = input("厂家:")
                    dgnum  = int(input("库存量:"))
                    dgprice = int(input("价格:"))
                    data = (dgno, dgname,dgpro,dgnum,dgprice)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功插入\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                    temp = input("输入你要插入的表格")
                except:
                    print("存在约束条件,不能插入该数据!")
                    print()
                    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                    temp = input("输入你要插入的表格")
                break
            if case(\'7\'):
                try:
                    sql = "INSERT INTO PD (dgno, pno, num) VALUES (\'%s\',\'%s\',%d)"
                    dgno = input("药品编号:")
                    dgno = (4 - len(dgno)) * \'0\' + dgno;
                    pno = input("患者编号:")
                    pno = (4 - len(pno)) * \'0\' + pno;
                    print(pno)
                    print(dgno)
                    num  = int(input("用药数量:"))
                    data = (dgno, pno, num)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功插入\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                    temp = input("输入你要插入的表格")
                except:
                    print("存在约束条件,不能插入该数据!")
                    print()
                    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                    temp = input("输入你要插入的表格")
                break
            if case(\'8\'):
                try:
                    sql = "INSERT INTO PN (pno, nno, content, time) VALUES (\'%s\',\'%s\',\'%s\',\'%s\')"
                    pno = input("患者编号:")
                    nno = input("护士工号:")
                    pno = (4 - len(pno)) * \'0\' + pno;
                    nno = (2 - len(nno)) * \'0\' + nno;
                    content = input("护理内容:")
                    time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                    data = (pno, nno, content, time)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功插入\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                    temp = input("输入你要插入的表格")
                except:
                    print("存在约束条件,不能插入该数据!")
                    print()
                    print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                    temp = input("输入你要插入的表格")
                break
            if case():
                print(\'无法识别操作码\')
                print()
                print("1--科室表/2--医生表/3--病房表/4--患者表/5--护士表/6--药品表/7--患者用药表/8--护士护理表/enter--结束输入///--default")
                temp = input("输入你要插入的表格")
                break

def update():
    # 修改数据
    print("1--修改药品库存/2--修改药品售价/3--修改患者使用药品数量/4--修改患者预计出院时间/5--修改患者房间号码/6--修改医生职务/enter--结束输入///--default")
    temp = input("输入你要修改的内容:")
    while temp:
        for case in switch(temp):
            if case(\'1\'):
                try:
                    sql = "UPDATE drug SET  dgnum = %d WHERE dgno = \'%s\' "
                    dgno = input("欲修改的药品编码:")
                    dgno = (4 - len(dgno)) * \'0\' + dgno
                    dgnum = int(input("修改后的库存:"))
                    data = (dgnum, dgno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功修改\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--修改药品库存/2--修改药品售价/3--修改患者使用药品数量/4--修改患者预计出院时间/5--修改患者房间号码/6--修改医生职务/enter--结束输入///--default")
                    temp = input("输入你要修改的内容:")
                except:
                    print("存在约束条件,不能修改该数据!")
                    print()
                    print("1--修改药品库存/2--修改药品售价/3--修改患者使用药品数量/4--修改患者预计出院时间/5--修改患者房间号码/6--修改医生职务/enter--结束输入///--default")
                    temp = input("输入你要修改的内容:")
                break
            if case(\'2\'):
                try:
                    sql = "UPDATE drug SET  dgprice = %d WHERE dgno = \'%s\' "
                    dgno = input("欲修改的药品编码:")
                    dgno = (4-len(dgno))*\'0\'+dgno
                    dgprice = int(input("修改后的药品价格:"))
                    data = (dgprice, dgno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功修改\', cursor.rowcount, \'条数据\')
                    print()
                    print(
                        "1--修改药品库存/2--修改药品售价/3--修改患者使用药品数量/4--修改患者预计出院时间/5--修改患者房间号码/6--修改医生职务/enter--结束输入///--default")
                    temp = input("输入你要修改的内容:")
                except:
                    print("存在约束条件,不能修改该数据!")
                    print()
                    print(
                        "1--修改药品库存/2--修改药品售价/3--修改患者使用药品数量/4--修改患者预计出院时间/5--修改患者房间号码/6--修改医生职务/enter--结束输入///--default")
                    temp = input("输入你要修改的内容:")
                break
            if case(\'3\'):
                try:
                    sql = "UPDATE PD SET  num = %d WHERE dgno = \'%s\' and pno = \'%s\' "
                    dgno = input("欲修改的药品编码:")
                    dgno = (4 - len(dgno)) * \'0\' + dgno
                    pno = input("欲修改的患者编码:")
                    pno = (4 - len(pno)) * \'0\' + pno
                    num = int(input("修改后的用药数量:"))
                    data = (num, dgno, pno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功修改\', cursor.rowcount, \'条数据\')
                    print()
                    print(
                        "1--修改药品库存/2--修改药品售价/3--修改患者使用药品数量/4--修改患者预计出院时间/5--修改患者房间号码/6--修改医生职务/enter--结束输入///--default")
                    temp = input("输入你要修改的内容:")
                except:
                    print("存在约束条件,不能修改该数据!")
                    print()
                    print(
                        "1--修改药品库存/2--修改药品售价/3--修改患者使用药品数量/4--修改患者预计出院时间/5--修改患者房间号码/6--修改医生职务/enter--结束输入///--default")
                    temp = input("输入你要修改的内容:")
                break
            if case(\'4\'):
                try:
                    sql = "UPDATE patient SET predictenddate = \'%s\'  WHERE pno = \'%s\' "
                    pno = input("欲修改的患者编码:")
                    pno = (4 - len(pno)) * \'0\' + pno
                    print("输入预计出院时间")
                    nian = input("年:")
                    yue = input("月:")
                    ri = input("日:")
                    predictenddate = nian + "-" + yue + "-" + ri
                    data = (predictenddate, pno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功修改\', cursor.rowcount, \'条数据\')
                    print()
                    print(
                        "1--修改药品库存/2--修改药品售价/3--修改患者使用药品数量/4--修改患者预计出院时间/5--修改患者房间号码/6--修改医生职务/enter--结束输入///--default")
                    temp = input("输入你要修改的内容:")
                except:
                    print("存在约束条件,不能修改该数据!")
                    print()
                    print(
                        "1--修改药品库存/2--修改药品售价/3--修改患者使用药品数量/4--修改患者预计出院时间/5--修改患者房间号码/6--修改医生职务/enter--结束输入///--default")
                    temp = input("输入你要修改的内容:")
                break
            if case(\'5\'):
                try:
                    sql = "UPDATE patient SET rno = \'%s\'  WHERE pno = \'%s\' "
                    pno = input("欲修改的患者编码:")
                    pno = (4 - len(pno)) * \'0\' + pno
                    rno = input("输入修改后的房间编号:")
                    rno = (4 - len(rno)) * \'0\' + rno
                    data = (rno, pno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功修改\', cursor.rowcount, \'条数据\')
                    print()
                    print(
                        "1--修改药品库存/2--修改药品售价/3--修改患者使用药品数量/4--修改患者预计出院时间/5--修改患者房间号码/6--修改医生职务/enter--结束输入///--default")
                    temp = input("输入你要修改的内容:")
                except:
                    print("存在约束条件,不能修改该数据!")
                    print()
                    print(
                        "1--修改药品库存/2--修改药品售价/3--修改患者使用药品数量/4--修改患者预计出院时间/5--修改患者房间号码/6--修改医生职务/enter--结束输入///--default")
                    temp = input("输入你要修改的内容:")
                break
            if case(\'6\'):
                try:
                    sql = "UPDATE doctor SET duty = \'%s\'  WHERE pno = \'%s\' "
                    pno = input("欲修改的医生编码:")
                    pno = (3 - len(pno)) * \'0\' + pno
                    duty = input("修改后的医生职务:")
                    data = (duty, pno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功修改\', cursor.rowcount, \'条数据\')
                    print()
                    print(
                        "1--修改药品库存/2--修改药品售价/3--修改患者使用药品数量/4--修改患者预计出院时间/5--修改患者房间号码/6--修改医生职务/enter--结束输入///--default")
                    temp = input("输入你要修改的内容:")
                except:
                    print("存在约束条件,不能修改该数据!")
                    print()
                    print(
                        "1--修改药品库存/2--修改药品售价/3--修改患者使用药品数量/4--修改患者预计出院时间/5--修改患者房间号码/6--修改医生职务/enter--结束输入///--default")
                    temp = input("输入你要修改的内容:")
                break
            if case():
                print(\'无法识别操作码\')
                print()
                print("1--修改药品库存/2--修改药品售价/3--修改患者使用药品数量/4--修改患者预计出院时间/5--修改患者房间号码/6--修改医生职务/enter--结束输入///--default")
                temp = input("输入你要修改的内容:")
                break

def select():
    # 查询数据
    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
    print("不输入直接回车enter结束查询///--default")
    temp = input("输入你要查询的内容:")
    while temp:
        for case in switch(temp):
            if case(\'1\'):
                try:
                    sql = "call sl_department(\'%s\')"
                    dno = input("医生编号:")
                    dno = (3 - len(dno))*\'0\'+dno
                    data = (dno)
                    cursor.execute(sql % data)
                    for row in cursor.fetchall():
                        print("医生姓名:%s\t科室名:%s" % row)
                    print(\'共查找出\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                except:
                    print("存在约束条件,不能查询该数据!")
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                break

            if case(\'2\'):
                try:
                    sql = "call sl_department_patientname(\'%c\')"
                    dpno = input("科室编号:")
                    data = (dpno)
                    cursor.execute(sql % data)
                    for row in cursor.fetchall():
                        print("患者名:%s\t患者编号:%s\t主治医生姓名:%s\t主治医生编号:%s\t" % row)
                    print(\'共查找出\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                except:
                    print("存在约束条件,不能查询该数据!")
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                break

            if case(\'3\'):
                try:
                    sql = "call sl_department_patientnum(\'%c\')"
                    dpno = input("科室编号:")
                    data = (dpno)
                    cursor.execute(sql % data)
                    for row in cursor.fetchall():
                        print("科室患者数:%d\t" % row)
                    print(\'共查找出\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                except:
                    print("存在约束条件,不能查询该数据!")
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                break

            if case(\'4\'):
                try:
                    sql = "call sl_doctor(\'%s\')"
                    pno = input("患者编号:")
                    pno = (4-len(pno))*\'0\'+pno
                    data = (pno)
                    cursor.execute(sql % data)
                    for row in cursor.fetchall():
                        print("医生姓名:%s\t职务:%s\t科室名:%s" % row)
                    print(\'共查找出\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                except:
                    print("存在约束条件,不能查询该数据!")
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                break

            if case(\'5\'):
                try:
                    sql = "call sl_doctor_patientnum(\'%s\')"
                    dno = input("医生编号:")
                    dno = (3 - len(dno))*\'0\'+dno
                    data = (dno)
                    cursor.execute(sql % data)
                    for row in cursor.fetchall():
                        print("医生主治的患者数量:%d\t" % row)
                    print(\'共查找出\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                except:
                    print("存在约束条件,不能查询该数据!")
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                break

            if case(\'6\'):
                try:
                    sql = "call sl_drug_patient(\'%s\')"
                    pno = input("患者编号:")
                    pno = (4-len(pno))*\'0\'+pno
                    data = (pno)
                    cursor.execute(sql % data)
                    for row in cursor.fetchall():
                        print("患者姓名:%s\t疾病:%s\t药名:%s\t数量:%d" % row)
                    print(\'共查找出\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                except:
                    print("存在约束条件,不能查询该数据!")
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                break

            if case(\'7\'):
                try:
                    sql = "call sl_money(\'%s\')"
                    pno = input("患者编号:")
                    pno = (4-len(pno))*\'0\'+pno
                    data = (pno)
                    cursor.execute(sql % data)
                    for row in cursor.fetchall():
                        print(" 应缴金额:%d" % row)
                    print(\'共查找出\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                except:
                    print("存在约束条件,不能查询该数据!")
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                break

            if case(\'8\'):
                try:
                    sql = "call sl_room(\'%c\')"
                    dpno = input("科室编号:")
                    data = (dpno)
                    cursor.execute(sql % data)
                    for row in cursor.fetchall():
                        print("科室名:%s\t病房编号:%s\t病房地址:%s\t" % row)
                    print(\'共查找出\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                except:
                    print("存在约束条件,不能查询该数据!")
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                break

            if case(\'9\'):
                try:
                    sql = "call sl_nurse(\'%s\')"
                    nno = input("护士编号:")
                    nno = (2-len(nno))*\'0\'+nno
                    data = (nno)
                    cursor.execute(sql % data)
                    for row in cursor.fetchall():
                        print("护士编号:%s\t护士姓名:%s" % row)
                    print(\'共查找出\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                except:
                    print("存在约束条件,不能查询该数据!")
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                break

            if case(\'10\'):
                try:
                    sql = "call sl_patient_nurse(\'%s\')"
                    pno = input("患者编号:")
                    pno = (4-len(pno))*\'0\'+pno
                    data = (pno)
                    cursor.execute(sql % data)
                    for row in cursor.fetchall():
                        print(" 患者名:%s\t病症:%s\t护理内容:%s\t护理时间:%s\t护士姓名:%s\t" % row)
                    print(\'共查找出\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                except:
                    print("存在约束条件,不能查询该数据!")
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                break

            if case(\'11\'):
                try:
                    sql = "call sl_patient_one_room(\'%s\')"
                    pno = input("患者编号:")
                    pno = (4-len(pno))*\'0\'+pno
                    data = (pno)
                    cursor.execute(sql % data)
                    for row in cursor.fetchall():
                        print(" 室友名:%s\t编号:%s\t" % row)
                    print(\'共查找出\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                except:
                    print("存在约束条件,不能查询该数据!")
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                break

            if case(\'12\'):
                try:
                    sql = "call sl_room_patient(\'%s\')"
                    rno = input("房间编号:")
                    rno = (4-len(rno))*\'0\'+rno
                    data = (rno)
                    cursor.execute(sql % data)
                    for row in cursor.fetchall():
                        print("患者编号:%s\t 姓名:%s\t" % row)
                    print(\'共查找出\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                except:
                    print("存在约束条件,不能查询该数据!")
                    print()
                    print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                    print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                    print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                    print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                    print("不输入直接回车enter结束查询///--default")
                    temp = input("输入你要查询的内容:")
                break
            if case():  # default
                print(\'please enter the OPcode...\')
                print()
                print("1--查询医生姓名及部门/2--查询科室的每个患者及其主治医师/3--查询科室就诊人数")
                print("4--查询患者的主治医生及其职务科室/5--查询医生主治的患者数量/6-查询患者用药情况")
                print("7--查询患者应缴金额/8--查询科室的病房/9--根据护士编号查询护士姓名")
                print("10--查询患者进行护理的时间,内容及负责护士/11--以患者编号查询室友/12--查询同一病房的患者")
                print("不输入直接回车enter结束查询///--default")
                temp = input("输入你要查询的内容:")
                break

def delete():
    print("1--删除患者/2--删除护士/3--删除药品/4--删除护理记录/5--删除用药记录/enter--结束输入///--default")
    temp = input("输入你要删除的内容:")
    while temp:
        for case in switch(temp):
            if case(\'1\'):
                try:
                    #删除数据
                    sql = "DELETE FROM PN  WHERE pno = \'%s\'"
                    pno = input("输入欲删除病人编号:")
                    print("删除护理记录!")
                    pno = (4 - len(pno)) * \'0\' + pno
                    data = (pno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功删除\', cursor.rowcount, \'条数据\')

                    print("删除用药记录!")
                    sql = "DELETE FROM PD  WHERE pno = \'%s\' "
                    data = (pno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功删除\', cursor.rowcount, \'条数据\')

                    print("删除患者记录!")
                    sql = "DELETE FROM patient  WHERE pno = \'%s\'"
                    data = (pno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功删除\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--删除患者/2--删除护士/3--删除药品/4--删除护理记录/5--删除用药记录/enter--结束输入///--default")
                    temp = input("输入你要删除的内容:")
                except:
                    print("存在约束条件,不能删除该数据!")
                    print()
                    print("1--删除患者/2--删除护士/3--删除药品/4--删除护理记录/5--删除用药记录/enter--结束输入///--default")
                    temp = input("输入你要删除的内容:")
                break

            if case(\'2\'):
                try:
                    #删除数据
                    sql = "DELETE FROM PN  WHERE nno = \'%s\'"
                    nno = input("输入欲删除护士编号:")
                    print("删除护理记录!")
                    nno = (2 - len(nno)) * \'0\' + nno
                    data = (nno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功删除\', cursor.rowcount, \'条数据\')

                    print("删除护士记录!")
                    sql = "DELETE FROM nurse  WHERE nno = \'%s\' "
                    data = (nno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功删除\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--删除患者/2--删除护士/3--删除药品/4--删除护理记录/5--删除用药记录/enter--结束输入///--default")
                    temp = input("输入你要删除的内容:")
                except:
                    print("存在约束条件,不能删除该数据!")
                    print()
                    print("1--删除患者/2--删除护士/3--删除药品/4--删除护理记录/5--删除用药记录/enter--结束输入///--default")
                    temp = input("输入你要删除的内容:")
                break

            if case(\'3\'):
                try:
                    #删除数据
                    sql = "DELETE FROM PD  WHERE dgno = \'%s\'"
                    dgno = input("输入欲删除药品编号:")
                    print("删除用药记录!")
                    dgno = (4 - len(dgno)) * \'0\' + dgno
                    data = (dgno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功删除\', cursor.rowcount, \'条数据\')

                    print("删除药品记录!")
                    sql = "DELETE FROM drug  WHERE dgno = \'%s\' "
                    data = (dgno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功删除\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--删除患者/2--删除护士/3--删除药品/4--删除护理记录/5--删除用药记录/enter--结束输入///--default")
                    temp = input("输入你要删除的内容:")
                except:
                    print("存在约束条件,不能删除该数据!")
                    print()
                    print("1--删除患者/2--删除护士/3--删除药品/4--删除护理记录/5--删除用药记录/enter--结束输入///--default")
                    temp = input("输入你要删除的内容:")
                break
            if case(\'4\'):
                try:
                    #删除数据
                    sql = "DELETE FROM PN  WHERE pno = \'%s\' and nno = \'%s\'"
                    pno = input("欲删除患者编号:")
                    pno = (4 - len(pno)) * \'0\' + pno
                    nno = input("欲删除护士编号:")
                    nno = (2 - len(nno)) * \'0\' + nno
                    data = (pno, nno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功删除\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--删除患者/2--删除护士/3--删除药品/4--删除护理记录/5--删除用药记录/enter--结束输入///--default")
                    temp = input("输入你要删除的内容:")
                except:
                    print("存在约束条件,不能删除该数据!")
                    print()
                    print("1--删除患者/2--删除护士/3--删除药品/4--删除护理记录/5--删除用药记录/enter--结束输入///--default")
                    temp = input("输入你要删除的内容:")
                break
            if case(\'5\'):
                try:
                    #删除数据
                    sql = "DELETE FROM PD  WHERE pno = \'%s\' and dgno = \'%s\'"
                    pno = input("欲删除患者编号:")
                    pno = (4 - len(pno)) * \'0\' + pno
                    dgno = input("欲删除药品编号:")
                    dgno = (4 - len(dgno)) * \'0\' + dgno
                    data = (pno, dgno)
                    cursor.execute(sql % data)
                    connect.commit()
                    print(\'成功删除\', cursor.rowcount, \'条数据\')
                    print()
                    print("1--删除患者/2--删除护士/3--删除药品/4--删除护理记录/5--删除用药记录/enter--结束输入///--default")
                    temp = input("输入你要删除的内容:")
                except:
                    print("存在约束条件,不能删除该数据!")
                    print()
                    print("1--删除患者/2--删除护士/3--删除药品/4--删除护理记录/5--删除用药记录/enter--结束输入///--default")
                    temp = input("输入你要删除的内容:")
                break

def close():
    # 关闭连接
    cursor.close()
    connect.close()

def main():
    print("a--insert/b--display/c--query/h--help/d--delete/\'\'--default")
    user_input = input(\'please enter the OPcode:\')
    while user_input:
        for case in switch(user_input):
            if case(\'a\'):  # 按下\'a\'键
                insert()
                print("a--insert/b--display/c--query/h--help/d--delete/\'\'--default")
                user_input = input(\'please enter the OPcode:\')
                break
            if case(\'b\'):  # 按下\'b\'键
                select()
                print("a--insert/b--display/c--query/h--help/d--delete/\'\'--default")
                user_input = input(\'please enter the OPcode:\')
                break
            if case("c"):  # 按下\'c\'键
                update()
                print("a--insert/b--display/c--query/h--help/d--delete/\'\'--default")
                user_input = input(\'please enter the OPcode:\')
                break
            if case("d"):  # 按下\'d\'键
                delete()
                print("a--insert/b--display/c--query/h--help/d--delete/\'\'--default")
                user_input = input(\'please enter the OPcode:\')
                break
            if case(\'h\'):  # 按下\'h\'键
                help_document()
                print()
                print("a--insert/b--display/c--query/h--help/d--delete/\'\'--default")
                user_input = input(\'please enter your OPcode:\')
                break
            if case():  # default
                print(\'please enter the OPcode...\')
                print("a--insert/b--display/c--query/h--help/d--delete/\'\'--default")
                user_input = input(\'please enter the OPcode:\')
                break
    close()

if __name__ == "__main__":
    main()

完整的SQL语句如下:

create schema hospital;
use hospital;

create table department
(
  dpname char(10) not null unique,
  dpno char(1) primary key,
  dpadr char(20),
  dptel char(20)
);
create table doctor
(
  dno char(3) primary key,
  dname char(20),
  duty char(20),
  dsex bit(1),
  dage int check (page>=0 and page <=150),
  dpno char(1),
  foreign key (dpno) references department(dpno)
);
create table room
(
  rno char(10) primary key ,
  radr char(20) unique,
  dpno char(5),
  foreign key (dpno) references department(dpno)
);
create table patient
(
  pno char(20) primary key,
  pname char(20) not null,
  psex bit(1),
  page int check (page>=0 and page <=150),
  dno char(3),
  rno char(10),
  illness char(20),
  startdate date,
  predictenddate date,
  foreign key (dno) references doctor(dno),
  foreign key (rno) references room(rno)
);
create table nurse
(
  nno char(2) primary key ,
  nname char(10) unique ,
  nsex bit(1),
  nage int
);
create table PN
(
  pno char(20),
  nno char(2),
  content char(20),
  time datetime,
  foreign key (pno) references patient(pno),
  foreign key (nno) references nurse(nno)
);
create table drug
(
  dgno char(4) primary key ,
  dgname char(20),
  dgpro char(20),
  dgnum int check(dgnum>=0),
  dgprice int check(dgprice>=0)
);
create table PD
(
  dgno char(4),
  pno char(4),
  num int check(num>=0),
  foreign key (dgno) references drug(dgno),
  foreign key (pno)  references patient(pno),
  primary key (dgno,pno)
);

insert into department values("内科","1","一号楼514","04512340987"),
                             ("外科","2","二号楼202","04514521234"),
                             ("妇科","3","一号楼421","04510987654"),
                             ("儿科","4","三号楼628","04511234567"),
                             ("神经科","5","一号楼555","04519283746"),
                             ("精神科","6","隔离所一栋01","04510987890"),
                             ("五官科","7","三号楼101","04511029281"),
                             ("放射线科","8","隔离所二栋11","04518888888"),
                             ("检验科","9","二号楼456","04518787878");
insert into doctor values ("101","李小明","中级医师",1,18,"1"),
                          ("102","赵二猫","正高级医师",1,56,"1"),
                          ("103","陈仁义","初级医师",0,20,"1"),
                          ("201","陈省","初级医师",0,21,"2"),
                          ("202","王雪清","副高级医师",0,32,"2"),
                          ("203","赵彩结","正高级医师",0,50,"2"),
                          ("301","王鹤男","中级医师",0,20,"3"),
                          ("302","王风","初级医师",0,31,"3"),
                          ("303","李文革","正高级医师",0,51,"3"),
                          ("401","钱求和","初级医师",0,24,"4"),
                          ("402","陈少杰","中级医师",1,26,"4"),
                          ("403","拉普拉斯","正高级医师",1,59,"4"),
                          ("501","赵意识","初级医师",0,31,"5"),
                          ("502","陈打野","中级医师",1,29,"5"),
                          ("503","欧上路","初级医师",1,31,"5"),
                          ("601","陈小希","初级医师",0,51,"6"),
                          ("602","陈欧皇","中级医师",1,29,"6"),
                          ("603","傅杰","副高级医师",0,46,"6"),
                          ("701","赵梦啥","初级医师",1,59,"7"),
                          ("702","王来文","正高级医师",1,32,"7"),
                          ("703","傅出","副高级医师",0,42,"7"),
                          ("801","王疯子","初级医师",0,21,"8"),
                          ("802","武曌","中级医师",1,25,"8"),
                          ("803","蔡子杰","初级医师",0,21,"8"),
                          ("901","谢好看","初级医师",0,21,"9"),
                          ("902","陈真帅","中级医师",1,20,"9"),
                          ("903","王猛","初级医师",1,21,"9");
insert into room values ("1101","一号楼101","1"),
                        ("1102","一号楼102","1"),
                        ("1103","一号楼103","1"),
                        ("2101","二号楼101","2"),
                        ("2102","二号楼102","2"),
                        ("2103","二号楼103","2"),
                        ("1401","一号楼401","3"),
                        ("1402","一号楼402","3"),
                        ("1403","一号楼403","3"),
                        ("1104","一号楼104","4"),
                        ("1105","一号楼105","5"),
                        ("1106","一号楼106","6"),
                        ("1407","一号楼407","7"),
                        ("1408","一号楼408","8"),
                        ("1409","一号楼409","9");
insert into patient values ("0001","赵一",1,20,"101","1101","左脚踝粉碎性骨折","2018-12-20","2019-01-28"),
                           ("0002","钱二",0,23,"201","2102","内出血","2018-11-22","2018-12-29"),
                           ("0003","竹三",0,19,"301","1401","妇科炎症","2018-12-22","2018-12-23"),
                           ("0004","李来武",1,6,"401","1104","多种抽动综合征","2018-11-10","2019-01-01"),
                           ("0005","王系民",1,52,"501","1105","帕金森综合征","2018-11-24","2018-12-25"),
                           ("0006","陈来文",0,54,"601","1106","强迫症","2018-12-15","2018-12-23"),
                           ("0007","代乘一",1,22,"701","1407","额骨骨髓炎","2018-12-24","2018-12-25"),
                           ("0008","高来基",0,34,"801","1408","核磁共振检测","2018-12-23","2018-12-26"),
                           ("0009","吴总会",0,43,"901","1409","艾滋病检测","2018-12-22","2018-12-27"),
                           ("0010","曹文龙",1,32,"102","1102","锁骨粉碎性骨折","2018-12-21","2019-01-25"),
                           ("0011","陈高轶",1,26,"202","2102","呼吸不畅","2018-12-19","2019-01-26"),
                           ("0012","陈温暖",1,29,"302","1401","子宫内膜炎","2018-12-18","2019-01-24"),
                           ("0013","牛群",0,3,"402","1104","结节性硬化","2018-12-17","2019-01-27"),
                           ("0014","李晶晶",0,61,"502","1105","老年性痴呆","2018-12-16","2019-01-28"),
                           ("0015","李沁颍",1,23,"602","1106","抑郁症","2018-12-15","2019-01-26"),
                           ("0016","刘馨雨",0,21,"702","1407","海绵窦血栓性静脉炎","2018-12-14","2019-01-25"),
                           ("0017","方子健",1,34,"802","1408","数字减影血管造影检测","2018-12-13","2019-01-26"),
                           ("0018","林威良",1,43,"902","1409","血液白细胞检测","2018-12-12","2019-01-24"),
                           ("0019","王恩琦",0,27,"103","1101","手指粉碎性骨折","2018-12-12","2019-01-26"),
                           ("0020","臧庆良",1,26,"203","2102","消化不良","2018-12-21","2019-01-29"),
                           ("0021","李欢欢",0,18,"303","1401","盆腔炎","2018-12-22","2019-01-31"),
                           ("0022","欧俊",1,6,"403","1104","小儿高热","2018-12-21","2019-01-30"),
                           ("0023","全淑敏",1,43,"503","1105","孤独症","2018-12-22","2019-01-01"),
                           ("0024","龚敬博",1,51,"603","1106","抑郁性神经症","2018-12-24","2019-01-22"),
                           ("0025","代除一",0,21,"703","1407","球后视神经炎","2018-12-23","2019-01-23"),
                           ("0026","郝凡",0,22,"803","1408","计算机X光检测","2018-12-22","2018-12-28"),
                           ("0027","黎小蓓",0,21,"903","1409","血液常规检查","2018-12-21","2018-12-22");
insert into nurse values ("01","黎晓蓓",0,21),
                         ("02","闫春竹",0,22),
                         ("03","马琳",0,23),
                         ("04","苏诗文",0,34),
                         ("05","刘颖",0,23),
                         ("06","卿菲雨",0,31),
                         ("07","徐龙",1,20),
                         ("08","曲芊羽",0,19);
insert into PN values ("0001","01","康复治疗1","2018-12-22 13:12:11"),
                      ("0002","02","康复治疗2","2018-12-23 15:12:22"),
                      ("0003","03","康复治疗3","2018-12-22 13:34:02"),
                      ("0004","04","康复治疗4","2018-12-23 14:32:23"),
                      ("0005","05","康复治疗1","2018-12-22 15:14:11"),
                      ("0006","06","康复治疗2","2018-12-23 16:14:11"),
                      ("0007","07","康复治疗3","2018-12-24 17:13:11"),
                      ("0008","08","康复治疗4","2018-12-24 18:14:11"),
                      ("0009","01","换药1","2018-12-22 19:27:21"),
                      ("0001","02","换药2","2018-12-23 12:16:14"),
                      ("0002","03","换药1","2018-12-26 13:15:15"),
                      ("0003","04","换药1","2018-12-23 14:11:15"),
                      ("0001","05","换药3","2018-12-24 15:42:16"),
                      ("0002","06","换药2","2018-12-22 16:24:17"),
                      ("0003","07","换药2","2018-12-23 17:14:18"),
                      ("0004","08","康复治疗1","2018-12-26 18:25:43"),
                      ("0005","01","康复治疗2","2018-12-24 19:52:12"),
                      ("0006","02","康复治疗3","2018-12-22 20:15:45"),
                      ("0007","03","康复治疗4","2018-12-24 21:43:34"),
                      ("0008","04","康复治疗5","2018-12-24 22:32:42"),
                      ("0009","05","康复治疗6","2018-12-22 23:23:24"),
                      ("0001","06","康复治疗7","2018-12-24 00:12:31"),
                      ("0005","07","康复治疗8","2018-12-25 01:53:41"),
                      ("0004","08","康复治疗9","2018-12-23 02:32:42");
insert into drug values("0001","注射用苄星青霉素","哈尔滨制药厂",123,24),
                       ("0002","三磷酸腺苷二钠","长春制药厂",213,34),
                       ("0003","复方氨林巴比妥注射液","沈阳制药厂",121,25),
                       ("0004","精蛋白生物合成人胰岛素注射液","北京制药厂",123,214),
                       ("0005","胞磷胆碱钠","上海制药厂",1010,28),
                       ("0006","艾司唑仑","广州制药厂",132,124),
                       ("0007","头孢氨苄","哈尔滨制药厂",12,43),
                       ("0008","异烟肼","长春制药厂",153,34),
                       ("0009","去乙酰毛花苷","北京制药厂",53,123),
                       ("0010","盐酸氟桂利嗪","广州制药厂",12,342),
                       ("0011","甲氰咪呱","哈尔滨制药厂",32,102),
                       ("0012","甲硫咪唑","广州制药厂",32,34),
                       ("0013","丁胺卡那霉素","广州制药厂",12,240),
                       ("0014","硝酸异山梨酯","哈尔滨制药厂",123,234),
                       ("0015","多潘立酮","长春制药厂",143,535),
                       ("0016","硫酸沙丁胺醇","北京制药厂",354,23),
                       ("0017","喷托维林","广州制药厂",3242,534),
                       ("0018","枸橼酸氯米芬","哈尔滨制药厂",544,53),
                       ("0019","枸橼酸他莫昔芬","广州制药厂",233,465),
                       ("0020","血塞通注射液","广州制药厂",532,42),
                       ("0021","注射用头孢替唑钠","哈尔滨制药厂",1232,23),
                       ("0022","注射用盐酸头孢替安","长春制药厂",124,27),
                       ("0023","复方愈创木酚磺酸钾口服溶液","北京制药厂",1344,23),
                       ("0024","克林霉素","广州制药厂",113,223),
                       ("0025","盐酸胺碘酮","哈尔滨制药厂",132,26),
                       ("0026","拉米夫定","广州制药厂",1030,23),
                       ("0027","头孢克肟颗粒","广州制药厂",1040,16),
                       ("0028","氟哌噻吨美利曲辛片","哈尔滨制药厂",123,53),
                       ("0029","盐酸克林霉素棕榈酸酯分散片","广州制药厂",135,53);
insert into PD values ("0001","0001",1),
                      ("0002","0001",2),
                      ("0001","0002",3),
                      ("0003","0001",1),
                      ("0004","0002",2),
                      ("0005","0001",3),
                      ("0004","0003",1),
                      ("0011","0003",2),
                      ("0005","0004",3),
                      ("0011","0022",1),
                      ("0012","0022",2),
                      ("0023","0013",3),
                      ("0023","0024",1),
                      ("0014","0022",2),
                      ("0015","0001",3),
                      ("0014","0002",1),
                      ("0021","0003",2),
                      ("0025","0004",3),
                      ("0021","0001",1),
                      ("0022","0001",2),
                      ("0021","0002",3),
                      ("0023","0003",1),
                      ("0024","0004",2),
                      ("0025","0005",3),
                      ("0024","0011",1),
                      ("0021","0021",2),
                      ("0025","0020",3),
                      ("0011","0019",1),
                      ("0022","0018",2),
                      ("0001","0017",3),
                      ("0003","0016",1),
                      ("0024","0015",2),
                      ("0015","0014",3),
                      ("0014","0013",1),
                      ("0021","0012",2),
                      ("0015","0011",3),
                      ("0006","0005",1),
                      ("0007","0005",2),
                      ("0008","0005",3),
                      ("0009","0005",1),
                      ("0010","0006",2),
                      ("0016","0006",3),
                      ("0017","0006",1),
                      ("0018","0006",2),
                      ("0019","0007",3),
                      ("0005","0007",1),
                      ("0025","0007",2),
                      ("0023","0007",3),
                      ("0024","0007",1),
                      ("0021","0008",2),
                      ("0028","0008",3),
                      ("0002","0008",1),
                      ("0001","0008",2),
                      ("0025","0009",3),
                      ("0011","0009",1),
                      ("0022","0010",2),
                      ("0001","0010",3),
                      ("0003","0010",1),
                      ("0024","0023",2),
                      ("0015","0025",3),
                      ("0014","0026",1),
                      ("0021","0027",2),
                      ("0013","0027",3),
                      ("0020","0021",1),
                      ("0007","0018",2),
                      ("0020","0018",3);

create procedure sl_drug_patient(in ppno char(4))
  begin
    select pname 患者姓名,illness 病症,dgname 药物名,num 数量
      from patient,drug,PD
        where patient.pno = pd.pno
          and drug.dgno = pd.dgno
            and pd.pno = ppno;
  end;
call sl_drug_patient("0001");

create procedure sl_doctor(in ppno char(4))
  begin
    select doctor.dname 医生姓名,doctor.duty 职务,dpname 科室名 from doctor,department
        where department.dpno = doctor.dpno
          and dno in
              (select dno from patient
               where ppno = pno);
  end;
call sl_doctor("0001");

create  procedure  sl_department(in ddno char(4))
begin
  select dname 医生姓名,dpname 科室名
    from department,doctor
      where department.dpno = doctor.dpno
        and doctor.dno = ddno;
end;
call sl_department("302");

create procedure sl_room(in ddpno char(1))
  begin
   select dpname 科室名,rno 病房编号,radr 病房地址
    from room,department
      where ddpno = room.dpno
       and room.dpno = department.dpno;
  end;
call sl_room("1");

create procedure sl_money(in ppno char(4))
  begin
    select sum(num * dgprice) 应缴金额
      from pd,patient,drug
        where pd.pno = patient.pno
          and drug.dgno = pd.dgno
            and patient.pno = ppno;
  end;
call sl_money("0023");

create procedure sl_doctor_patientnum(in ddno char(4))
  begin
    select count(*) 医生主治的患者数量 from patient
      where patient.dno = ddno;
  end;
call sl_doctor_patientnum("102");

create procedure sl_department_patientnum(in ddpno char(1))
  begin
    select count(*) 科室患者数 from patient,doctor,department
        where patient.dno = doctor.dno
          and department.dpno = doctor.dpno
            and ddpno = department.dpno ;
  end;
call sl_department_patientnum("2");

create procedure sl_department_patientname(in ddpno char(1))
  begin
    select pname 患者名,patient.pno 患者编号,dname 主治医师姓名,doctor.dno 主治医师编号
      from patient,doctor,department
        where patient.dno = doctor.dno
          and department.dpno = doctor.dpno
            and ddpno = department.dpno ;
  end;
call sl_department_patientname("1");

create procedure sl_nurse(in nnno char(2))
  begin
    select nno 护士编号,nname 护士姓名 from nurse
        where nno = nnno;
  end;
call sl_nurse("05");

create procedure sl_patient_nurse(in ppno char(4))
  begin
    select pname,illness,content,time,nname
    from nurse,patient,pn
        where nurse.nno = pn.nno
        and patient.pno = pn.pno
        and patient.pno = ppno;
  end;
call sl_patient_nurse("0002");

create procedure sl_patient_one_room(in ppno char(4))
  begin
    select A.pname,A.pno from patient A
        where rno in
              (select B.rno from patient B
              where B.pno=ppno);
  end;
call sl_patient_one_room("0002");

create procedure sl_room_patient(in rrno char(4))
  begin
    select pno,pname from patient
        where rno = rrno;
  end;
call sl_room_patient("1407");

create procedure del_patient(in ppno char(4))
  begin
    delete from PD where ppno = PD.pno;
    delete from patient where ppno = patient.pno;
  end;
call del_patient("0027");

create procedure del_drug(in ddgno char(4))
  begin
    delete from PD where ddgno = PD.dgno;
    delete from drug where ddgno = drug.dgno;
  end;
call del_drug("0029");

 

版权声明:本文为cxl-原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/cxl-/p/14487935.html