Beispiel #1
0
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 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_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)
Beispiel #5
0
def login():
    if request.method == 'POST':
        name = request.form['name']
        password = request.form['password']
        error = None
        cursor.execute(sql_select_staff,name)
        user = cursor.fetchone()

        if user is None:
            error = 'Incorrect name.'
        elif password != user['password']:
            error = 'Incorrect password.'

        if error is None:
            session.clear()
            session['user_id'] = user['staff_id']
            session['user_name'] = user['name']
            session['role'] = user['role']
            # return redirect(url_for('calculation_F1.index'))
            print("success")
            return render_template('nav.html', role=user['role'], area=get_staff_area(name), name=name)

        flash(error)

    return render_template('auth/login.html')
Beispiel #6
0
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 nucleic_test():
    patient_id = request.args.get("patient_id")
    test_date = request.args.get("test_date")
    return render_template('ward_nurse/nucleic_report_form.html',
                           name=session['user_name'],
                           role=session['role'],
                           area=get_staff_area(session['user_name']),
                           patient_id=patient_id,
                           test_date=test_date)
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 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']))
Beispiel #10
0
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']))
Beispiel #11
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 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)
Beispiel #13
0
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']))
Beispiel #14
0
def new_nucleic_test():
    return render_template('doctor/new_nucleic_test.html', name=session["user_name"], role=session["role"], area=get_staff_area(session["user_name"]), patient_id = request.args.get('patient_id'))
Beispiel #15
0
def show_ward_nurse(area_name):
    sql = "select * from staff natural join staff_area where role='ward_nurse' and area=%s"
    cursor.execute(sql, area_name)
    result = cursor.fetchall()
    return render_template('doctor/head_nurse.html', name=session["user_name"], role=session["role"], area=get_staff_area(session["user_name"]), head_nurses=result)
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'])
Beispiel #17
0
def modify_state_of_illness():
    patient_id = request.args.get("patient_id")
    return render_template("doctor/modify_state_of_illness.html",name=session['user_name'], role=session['role'],
                           area=get_staff_area(session['user_name']), patient_id=patient_id)
def report():
    return render_template("ward_nurse/report.html",
                           patient_id=request.args.get('patient_id'),
                           name=session['user_name'],
                           role=session['role'],
                           area=get_staff_area(session['user_name']))