def commit_modify(): patient_id = request.form['patient_id'] area = request.form['area'] new_nurse_id = has_nurse(area) new_bed_id = has_space(area) if new_nurse_id == 0 or new_bed_id == 0: message = '暂时无法插入' print(message) update_patient = "update patient set state_of_illness=%s where patient_id=%s" cursor.execute(update_patient, [area, patient_id]) db.commit() return render_template("nav.html",name=session['user_name'], role=session['role'], area=get_staff_area(session['user_name']), message=message) update_patient = "update patient set state_of_illness=%s, nurse_id=%s where patient_id=%s" update_area = "update patient_area set area =%s where patient_id=%s" update_old_bed = "update bed set patient_id=null where patient_id=%s" update_new_bed = "update bed set patient_id=%s where bed_id=%s" try: cursor.execute(update_patient,[area,new_nurse_id,patient_id]) cursor.execute(update_area,[area,patient_id]) cursor.execute(update_old_bed,patient_id) cursor.execute(update_new_bed,[patient_id,new_bed_id]) except Exception as e: db.rollback() print("在更改病人病情状况时发生错误", e) db.commit() old_area = get_staff_area(session['user_name']) if not insert_patient_from_isolated(old_area): insert_patient_another(old_area) return render_template("nav.html", name=session['user_name'], role=session['role'], area=get_staff_area(session['user_name']))
def insert_patient_another(area): from auth import cursor from entry import db from emergency_nurse import has_nurse, has_space find_another = "select patient_id from patient natural join patient_area where state_of_illness=%s and" \ " state_of_illness <> area and life_status='alive' limit 1" cursor.execute(find_another, area) results = cursor.fetchall() if not len(results) == 1: return False nurse_id = has_nurse(area) patient_id = results[0]['patient_id'] bed_id = has_space(area) update_patient = "update patient set nurse_id=%s where patient_id=%s" update_patient_area = 'update patient_area(patient_id,area) set area=%s where patient_id=%s' update_original_bed = "update bed set patient_id=null where patient_id=%s" update_new_bed = "update bed set patient_id=%s where bed_id=%s" try: cursor.execute(update_patient, [nurse_id, patient_id]) cursor.execute(update_patient_area, [area, patient_id]) cursor.execute(update_original_bed, patient_id) cursor.execute(update_new_bed, [patient_id, bed_id]) except Exception as e: db.rollback() print("在调用自动将不符合区域病人转区时发生异常", e) db.commit() return True
def add_nurse(): area = get_staff_area(session['user_name']) nurse_id = request.args.get("staff_id") ad_nurse = "insert into staff_area(staff_id,area) values(%s,%s)" cursor.execute(ad_nurse, [nurse_id,area]) db.commit() return render_template("nav.html", name=session['user_name'], area=get_staff_area(session['user_name']), role=session['role'],staff_id=session['user_id'])
def commit_nucleic_test(): patient_id = request.form['patient_id'] test_date = request.form['test_date'] test_result = request.form['test_result'] update_report = "update nucleic_test set test_result=%s where patient_id=%s and test_date=%s" cursor.execute(update_report, [test_result, patient_id, test_date]) db.commit() return render_template('nav.html', name=session['user_name'], role=session['role'], area=get_staff_area(session['user_name']))
def commit_report(): area = get_staff_area(session["user_name"]) if request.method == "POST": patient_id = request.form['patient_id'] patient_temperature = request.form['temperature'] patient_symptom = request.form['symptom'] patient_life_status = request.form['life_status'] test_date = datetime.datetime.strptime(request.form['test_date'], '%Y-%m-%d').date() find_latest_date = "select test_date from patient natural join temperature_test" \ " where nurse_id=%s and patient_id =%s order by test_date desc limit 1" cursor.execute(find_latest_date, [session["user_id"], patient_id]) result = cursor.fetchall() if len(result) > 0 and compare(result[0]['test_date'], test_date): message = '插入时间不符合要求' print(message) return render_template('nav.html', name=session['user_name'], role=session['role'], area=get_staff_area(session['user_name']), message=message) update_patient = "update patient set life_status=%s,symptom=%s where patient_id=%s" insert_temperature_test = "insert into temperature_test" \ "(patient_id,body_temperature,test_date) values (%s,%s,%s)" remove_patient = "delete from patient_area where patient_id=%s" remove_bed = "update bed set patient_id = null where patient_id=%s" remove_nurse = "update patient set nurse_id = null where patient_id =%s" try: cursor.execute(update_patient, [patient_life_status, patient_symptom, patient_id]) cursor.execute(insert_temperature_test, [patient_id, patient_temperature, test_date]) if patient_life_status == 'dead': cursor.execute(remove_patient, patient_id) cursor.execute(remove_bed, patient_id) cursor.execute(remove_nurse, patient_id) except Exception as e: db.rollback() print("添加病人日常信息时发生异常", e) db.commit() if patient_life_status == 'dead': if not insert_patient_from_isolated(area): insert_patient_another(area) return render_template('nav.html', name=session['user_name'], role=session['role'], area=get_staff_area(session['user_name']))
def commit_new_nucleic_test(): patient_id = request.form['patient_id'] test_date = datetime.datetime.strptime(request.form['test_date'],'%Y-%m-%d').date() find_latest_date = "select test_date from patient natural join nucleic_test" \ " where patient_id =%s order by test_date desc limit 1" cursor.execute(find_latest_date,patient_id) latest_date = cursor.fetchone()["test_date"] if compare(latest_date,test_date): message = '时间不符合要求' print(message) render_template("nav.html",name=session['user_name'], role=session['role'], area=get_staff_area(session['user_name']), message=message) insert_new_test = 'insert into nucleic_test(patient_id,test_date) values(%s,%s)' cursor.execute(insert_new_test,[patient_id,test_date]) db.commit() return render_template('nav.html', name=session['user_name'], role=session['role'], area=get_staff_area(session['user_name']))
def discharge(): area = get_staff_area(session["user_name"]) patient_id = request.args.get('patient_id') modify_patient = "update patient set life_status='discharged' where patient_id=%s" remove_patient = "delete from patient_area where patient_id=%s" remove_bed = "update bed set patient_id = null where patient_id=%s" remove_nurse = "update patient set nurse_id = null where patient_id =%s" try: cursor.execute(modify_patient, patient_id) cursor.execute(remove_patient, patient_id) cursor.execute(remove_bed, patient_id) cursor.execute(remove_nurse, patient_id) except Exception as e: db.rollback() print("移除出院病人床位时出错", e) db.commit() if not insert_patient_from_isolated(area): insert_patient_another(area) return render_template('nav.html', name=session['user_name'], role=session['role'], area=get_staff_area(session['user_name']))
def insert_patient_from_isolated(area): from auth import cursor from entry import db from emergency_nurse import has_nurse, has_space find_isolated = "select patient_id from patient where nurse_id is null and life_status='alive' and state_of_illness=%s limit 1" cursor.execute(find_isolated, area) results = cursor.fetchall() if not len(results) == 1: return False patient_id = results[0]['patient_id'] nurse_id = has_nurse(area) bed_id = has_space(area) update_patient = "update patient set nurse_id=%s where patient_id=%s" insert_patient_area = 'insert into patient_area(patient_id,area) values (%s,%s)' update_bed = "update bed set patient_id=%s where bed_id=%s" try: cursor.execute(update_patient, [nurse_id, patient_id]) cursor.execute(insert_patient_area, [patient_id, area]) cursor.execute(update_bed, [patient_id, bed_id]) except Exception as e: db.rollback() print("在调用自动将隔离区病人转为住院时发生异常", e) db.commit() return True
def new_patient(): if request.method == 'GET': return render_template("emergency_nurse/new_patient.html", username=session['user_name'], role=session['role'], area=get_staff_area(session['user_name'])) else: patient_name = request.form['name'] patient_gender = request.form['gender'] patient_address = request.form['address'] patient_state_of_illness = request.form['state_of_illness'] patient_age = request.form['age'] test_date = request.form['test_date'] room_id = has_space(patient_state_of_illness) nurse_id = has_nurse(patient_state_of_illness) if nurse_id == 0 or room_id == 0: print("here") if nurse_id == 0: message = '没有空闲的护士' else: message = '没有空余房间' insert_patient = "insert into patient(name,gender,address,state_of_illness,age," \ "life_status) values(%s,%s,%s,%s,%s,'alive')" insert_nucleic_test = "insert into nucleic_test (test_date,test_result,patient_id) values(%s,'positive',%s)" try: cursor.execute(insert_patient, [ patient_name, patient_gender, patient_address, patient_state_of_illness, patient_age ]) sql_get_patient_id = "select patient_id from patient where name=%s" cursor.execute(sql_get_patient_id, patient_name) patient_id = cursor.fetchone()["patient_id"] cursor.execute(insert_nucleic_test, [test_date, patient_id]) except Exception as e: db.rollback() print("添加新病人至隔离区失败", e) db.commit() return render_template("nav.html", username=session['user_name'], role=session['role'], area=get_staff_area(session['user_name']), message=message) insert_patient = "insert into patient(name,gender,address,state_of_illness,age," \ "nurse_id,life_status) values(%s,%s,%s,%s,%s,%s,'alive')" insert_nucleic_test = "insert into nucleic_test (test_date,test_result,patient_id) values(%s,'positive',%s)" insert_patient_area = "insert into patient_area(patient_id,area) values(%s,%s)" update_room = "update bed set patient_id=%s where bed_id =%s" try: cursor.execute(insert_patient, [ patient_name, patient_gender, patient_address, patient_state_of_illness, patient_age, nurse_id ]) sql_get_patient_id = "select patient_id from patient where name=%s" cursor.execute(sql_get_patient_id, patient_name) patient_id = cursor.fetchone()["patient_id"] cursor.execute(insert_patient_area, [patient_id, patient_state_of_illness]) cursor.execute(insert_nucleic_test, [test_date, patient_id]) cursor.execute(update_room, [patient_id, room_id]) except Exception as e: db.rollback() print('添加新病人失败', e) db.commit() return render_template("nav.html", username=session['user_name'], role=session['role'], area=get_staff_area(session['user_name']))
def delete_nurse(): nurse_id = request.args.get("staff_id") del_nurse = "delete from staff_area where staff_id=%s" cursor.execute(del_nurse, nurse_id) db.commit() return render_template("nav.html", name=session['user_name'], area=get_staff_area(session['user_name']), role=session['role'],staff_id=session['user_id'])