def insert_patient(self): session = DBSession() oids = [ office['id'] for office in self.offices if office['name'] == self.office_name_var.get() ] dids = [ doctor['id'] for doctor in self.doctors if doctor['name'] == self.doctor_var.get() ] rids = [ room['id'] for room in self.rooms if room['room_number'] == self.room_var.get() ] gender = self.gender_var.get() try: patient = Patient(did=dids[0], rid=rids[0], oid=oids[0], history_number=self.history_number_var.get(), name=self.name_var.get(), gender=gender, age=self.age_var.get(), diagnose=self.dig_var.get()) messagebox.showinfo('成功', '新建患者成功!') session.add(patient) except Exception as _: messagebox.showinfo('失败', '新建患者失败') session.commit() session.close() self.refresh_table()
def insert_office(self): session = DBSession() try: office = Office( office_name=self.office_name_var.get(), office_address=self.office_addr_var.get(), office_telephone=self.office_tele_var.get() ) session.add(office) session.commit() messagebox.showinfo('成功', '新建科室成功!') except Exception as _: messagebox.showerror('失败', '新建科室失败,科室已存在') session.close() self.refresh_table()
def insert_room(self): session = DBSession() oids = [ office['id'] for office in self.offices if office['name'] == self.office_name_var.get() ] try: room = Room(room_number=self.room_number_var.get(), bed_number=int(self.room_bed_number_var.get()), oid=oids[0]) session.add(room) session.commit() messagebox.showinfo('成功', '新建病房成功!') except Exception as _: messagebox.showerror('失败', '新建病房失败,病房可能已存在或科室选择错误') session.close() self.refresh_table()
def register(self): username = self.username_var.get() password = self.password_var.get() m = hashlib.md5() m.update(password.encode()) pass_hash = m.hexdigest() session = DBSession() login_dao = Login_dao( username=username, password=pass_hash ) try: session.add(login_dao) session.commit() except: messagebox.showerror("错误", "用户名已存在或不可为空!") else: messagebox.showinfo("成功", f"用户{username}已注册成功!") finally: session.close()
def insert_doctor(self): session = DBSession() oids = [ office['id'] for office in self.offices if office['name'] == self.office_name_var.get() ] gender = self.gender_var.get() try: room = Doctor(work_number=self.work_number_var.get(), name=self.name_var.get(), gender=gender, age=self.age_var.get(), title=self.title_var.get(), oid=oids[0]) session.add(room) session.commit() messagebox.showinfo('成功', '新建医生成功!') except Exception as _: messagebox.showerror('失败', '新建医生失败,医生可能已存在') session.close() self.refresh_table()