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 change(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() patient: Patient = session.query(Patient).filter_by( history_number=self.history_number_var.get()).first() try: if patient: patient.did = dids[0] patient.rid = rids[0] patient.oid = oids[0] patient.name = self.name_var.get() patient.gender = gender patient.age = self.age_var.get() patient.diagnose = self.dig_var.get() messagebox.showinfo('成功', '修改病人信息成功') else: messagebox.showerror('错误', '找不到病人') except Exception as _: messagebox.showinfo('失败', '修改病人信息失败') session.commit() session.close() self.refresh_table()
def tb_bind(self, event): id_ = None for item in self.tb.selection(): item_text = self.tb.item(item, "values") id_ = item_text[0] if id_: session = DBSession() try: o: Office = session.query(Office).filter_by(id=id_).first() session.delete(o) session.commit() except: messagebox.showerror('错误', '该科室已被病房或医生绑定') session.close() self.refresh_table()
def tb_bind(self, event): id_ = None for item in self.tb.selection(): item_text = self.tb.item(item, "values") id_ = item_text[0] if id_: session = DBSession() try: p: Patient = session.query(Patient).filter_by(id=id_).first() session.delete(p) session.commit() except: messagebox.showerror('错误', '该病人已被其他关系绑定') session.close() self.refresh_table()
def change(self): name = self.office_name_var.get() session = DBSession() office: Optional[Office] = session.query(Office).filter_by( office_name=name ).first() if office: office.office_address = self.office_addr_var.get() office.office_telephone = self.office_tele_var.get() session.commit() messagebox.showinfo('成功', '修改科室信息成功') else: messagebox.showerror('找不到科室', f'找不到名为 {name} 的科室.') 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()
def change(self): session = DBSession() oids = [ office['id'] for office in self.offices if office['name'] == self.office_name_var.get() ] num = self.room_number_var.get() room: Optional[Room] = session.query(Room).filter_by( room_number=num).first() try: if room: room.bed_number = int(self.room_bed_number_var.get()) room.oid = oids[0] session.commit() messagebox.showinfo('成功', '病房信息修改成功!') else: messagebox.showerror('错误', '找不到病房!') except Exception as _: messagebox.showinfo('失败', '病房信息修改失败') session.close() self.refresh_table()
def refresh_table(self): for item in self.tb.get_children(): self.tb.delete(item) session = DBSession() rooms: List[Tuple] = session.query( Room, Office.office_name).join(Office).filter().all() self.rooms = [{ 'id': room[0].id, 'room_number': room[0].room_number, 'bed_number': room[0].bed_number, 'office_name': room[1] } for room in rooms] session.commit() session.close() print(self.rooms) for room in self.rooms: self.tb.insert("", 0, values=[ room['id'], room['room_number'], room['bed_number'], room['office_name'], ])
def change(self): session = DBSession() oids = [ office['id'] for office in self.offices if office['name'] == self.office_name_var.get() ] gender = self.gender_var.get() doctor: Doctor = session.query(Doctor).filter_by( work_number=self.work_number_var.get()).first() try: if doctor: doctor.name = self.name_var.get() doctor.gender = gender doctor.age = self.age_var.get() doctor.title = self.title_var.get() doctor.oid = oids[0] session.commit() messagebox.showinfo('成功', '修改医生信息成功!') else: messagebox.showerror('错误', '找不到医生') except Exception as _: messagebox.showinfo('失败', '新建医生失败') session.close() self.refresh_table()