def is_patient_discharged(patient_id): from auth import cursor sql_temperature = "select * from temperature_test where patient_id =%s order by test_date desc limit 3" sql_nucleic = "select * from nucleic_test where patient_id=%s order by test_date desc limit 2 " cursor.execute(sql_temperature, patient_id) temperature_list = cursor.fetchall() cursor.execute(sql_nucleic, patient_id) nucleic_list = cursor.fetchall() if is_temperature(temperature_list) & is_nucleic(nucleic_list): return "是" else: return "否"
def has_space(area): sql = "select bed_id from bed where area=%s and patient_id is null order by bed_id limit 1" cursor.execute(sql, area) result = cursor.fetchall() if len(result) < 1: return 0 return result[0]["bed_id"]
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 get_symptoms(patient_id): from auth import cursor from entry import sql_select_patient_symptoms sql = sql_select_patient_symptoms % patient_id cursor.execute(sql) symptoms_list = cursor.fetchall() return symptoms_list
def bed(): area = get_staff_area(session['user_name']) get_beds = "select * from bed natural left outer join patient where area =%s" cursor.execute(get_beds,area) results = cursor.fetchall() beds = [] for result in results: beds.append(result) return render_template("head_nurse/bed.html", name=session['user_name'], area=area, role=session['role'], staff_id=session['user_id'], beds=beds)
def nurse(): area = get_staff_area(session['user_name']) get_nurse = "select * from staff natural join staff_area where area=%s and role='ward_nurse'" cursor.execute(get_nurse, area) results = cursor.fetchall() nurses = [] for result in results: nurse = [] nurse_id = result['staff_id'] get_patients = "select patient_id from patient where nurse_id=%s" cursor.execute(get_patients, nurse_id) patients = list(cursor.fetchall()) nurse.append(result['staff_id']) nurse.append(result['name']) nurse.append(result['gender']) nurse.append(result['age']) nurse.append(result['area']) nurse.append(patients) if len(patients) == 0: nurse.append("没有病人") nurses.append(nurse) get_free_nurse = "select * from staff natural left outer join staff_area where area is null and role='ward_nurse'" cursor.execute(get_free_nurse) free_nurses_results = cursor.fetchall() free_nurses = [] for result in free_nurses_results: nurse = [] nurse.append(result['staff_id']) nurse.append(result['name']) nurse.append(result['gender']) nurse.append(result['age']) free_nurses.append(nurse) return render_template("head_nurse/nurse.html", name=session['user_name'], area=area, role=session['role'], staff_id=session['user_id'], nurses=nurses, free_nurses=free_nurses)
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 show_nucleic_tests_to_report(): area = get_staff_area(session['user_name']) if not area: return render_template('nav.html', name=session['user_name'], role=session['role'], area=get_staff_area(session['user_name'])) find_to_report = "select * from patient natural join nucleic_test where nurse_id=%s and test_result is null" cursor.execute(find_to_report, session["user_id"]) nucleic_reports = cursor.fetchall() return render_template('ward_nurse/nucleic_report.html', name=session['user_name'], role=session['role'], area=area, nucleic_reports=nucleic_reports)
def has_nurse(area): limit_number = 0 if area == 'soft': limit_number = 3 elif area == 'urgent': limit_number = 2 elif area == 'very_urgent': limit_number = 1 sql = "select staff_id from staff natural join staff_area where area =%s and role='ward_nurse' " cursor.execute(sql, area) results = cursor.fetchall() list_nurses = [] for result in results: list_nurses.append(result["staff_id"]) for nurse_id in list_nurses: find_related = "select count(nurse_id) as count_nurse from patient where nurse_id = %s" cursor.execute(find_related, nurse_id) count = cursor.fetchone()["count_nurse"] if count < limit_number: return nurse_id return 0
def all_patient(): from util import is_patient_discharged, get_patient_area, get_symptoms, get_temperature, get_staff_area area = get_staff_area(session['user_name']) if session["role"] == 'doctor' or session["role"] == 'head_nurse': sql = "select * from patient natural join patient_area where patient_area.area =%s" cursor.execute(sql, area) elif session["role"] == "ward_nurse": sql = "select * from patient natural join patient_area where nurse_id =%s" cursor.execute(sql, session["user_id"]) else: sql = "select * from patient natural left outer join patient_area" cursor.execute(sql) raw_patient_list = cursor.fetchall() patient_list = [] for patient in raw_patient_list: patient_id = patient['patient_id'] list = [] list.append(patient_id) list.append(patient['name']) list.append(patient['gender']) list.append(patient['address']) list.append(get_temperature(patient_id)) list.append(patient['life_status']) list.append(patient['state_of_illness']) list.append(patient["symptom"]) list.append(get_patient_area(patient_id)) list.append(is_patient_discharged(patient_id)) list.append(patient["area"]) patient_list.append(list) return render_template('all_patient.html', name=session['user_name'], staff_id=session['user_id'], role=session['role'], area=get_staff_area(session['user_name']), patients=patient_list)
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