def adding_account(): if request.method == 'POST': ssn = request.form['patient_ssn'] first_name = request.form['patient_first_name'] last_name = request.form['patient_last_name'] age = request.form['patient_age'] email = request.form['patient_email'] address = request.form['patient_address'] city = request.form['patient_city'] state = request.form['patient_state'] zipcode = request.form['patient_zipcode'] phone = request.form['patient_phone_number'] date_of_birth = request.form['patient_date_of_birth'] cursor = db.cursor() cursor.execute("""INSERT INTO User VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, null)""", (str(ssn) , str(first_name), str(last_name), str(age), str(email), str(address) , str(city), str(state), str(zipcode), str(phone), str(date_of_birth))) cursor.execute("""INSERT INTO Patient VALUES (%s)""", (str(ssn), )) db.commit() return render_template('new_account.html', data_return=[ssn , first_name, last_name, age, email, address, city, state, zipcode, phone, date_of_birth]) else: return render_template('adding_new_patient.html')
def update_appointment(appointment): if request.method == "POST": cursor = db.cursor() symptoms = request.form['symptoms'] notes = request.form['notes'] if len(request.form) <= 3: # update appointment info cursor.execute("UPDATE Appointment set symptoms=%s, notes=%s where appointment_sn=%s", (symptoms, notes, appointment)) db.commit() else: cursor.execute("UPDATE Appointment set symptoms=%s, notes=%s where appointment_sn=%s", (symptoms, notes, appointment)) db.commit() medicine_name = request.form['medicine_name'] medicine_shape = request.form['medicine_shape'] medicine_producer = request.form['medicine_producer'] medicine_unit_per_time = request.form['medicine_unit_per_time'] medicine_total = request.form['medicine_total'] # checking existing medicine cursor.execute("SELECT * from Medicine where medicine_name=%s and shape=%s and producer=%s" , (medicine_name, medicine_shape, medicine_producer)) medicine_info = cursor.fetchone() if medicine_info == None: return redirect(url_for('showing_appointment_update_info', appointment=appointment, set_value=1)) else: cursor.execute("UPDATE Appointment_medicine set medicine_name=%s, shape=%s, producer=%s where appointment_sn=%s" , (medicine_name, medicine_shape, medicine_producer, appointment)) db.commit() checking, return_data = getting_all_appointment_info(appointment) return render_template('showing_appointment.html', data=return_data)
def checking_patient_account(patient_ssn): cursor = db.cursor() cursor.execute("SELECT * from User where ssn=" + "'" + patient_ssn + "'") data = cursor.fetchone() if data == None: return True else: return False
def delete_appointment(): if request.method == 'GET': return render_template('delete_appointment.html') elif request.method == 'POST': cursor = db.cursor() appointment_number = request.form['appointment_number'] cursor.execute("SELECT * from Appointment where appointment_sn=(%s)", (appointment_number, )) data = cursor.fetchone() if data == None: return render_template('delete_appointment.html', data='Appointment did not exist') elif data[1] != None: return render_template('delete_appointment.html', data='You can not delete this appointment') else: cursor.execute("DELETE FROM Appointment Where appointment_sn=(%s)" , (appointment_number, )) db.commit() return render_template('delete_appointment.html', data="We apologizes when we could not help you. Hope you will get well sone!!!")
def finding_patient(): if request.method == "POST": if request.form['search_string'] == '': return render_template('patient.html', not_found="Please input user's email to search") cursor = db.cursor() cursor.execute("SELECT * from User where email=" + "'" + request.form['search_string'] + "'") data = cursor.fetchone() if data == None: return render_template('patient.html', not_found="The result not found") else: cursor.execute("SELECT * from Patient where patient_ssn=" + "'" + str(data[0]) + "'") data1 = cursor.fetchone() if data1 == None: return render_template('patient.html', not_found="The result not found") return render_template('patient.html', data=data) if request.method == 'GET': return render_template('patient.html')
def create_appointment(): if request.method == 'GET': return render_template('making_new_appointment.html') elif request.method == 'POST': patient_ssn = request.form['patient_ssn'] symptoms = request.form['symptoms'] if patient_ssn == '' or symptoms == '': return render_template('making_new_appointment.html') elif checking_patient_account(patient_ssn): messages = json.dumps({'patient_ssn':patient_ssn}) return redirect(url_for(".creating_new_account", messages=messages)) else: appointment_number = add_appointment_to_database(db.cursor(), patient_ssn, symptoms) return render_template('making_new_appointment.html', data=appointment_number)
def getting_all_appointment_info(appointment): cursor = db.cursor() # appointment information cursor.execute("SELECT * from Appointment where appointment_sn=(%s)", (appointment, )) appointment_info = cursor.fetchone() if appointment_info == None: return False, "This appointment does not exist" else: return_data = [str(x) for x in appointment_info] # medicine of appointment information cursor.execute("SELECT * from Appointment_medicine where appointment_sn=(%s)", (appointment, )) appointment_medicine_info = cursor.fetchone() if appointment_medicine_info == None: return True, return_data else: return_data.extend([str(x) for x in appointment_medicine_info[1:]]) return True, return_data
def finding_medicine(): if request.method == 'GET': return render_template('medicine.html') elif request.method == 'POST': medicine_name = request.form['medicine_name'] type_of_medicine_shape = request.form['type_of_medicine_shape'] producer = request.form['medicine_company'] # db cursor cursor = db.cursor() if producer == '' or type_of_medicine_shape == '' or medicine_name == '': return render_template('medicine.html', not_found='Please input enough information that helps us find the result') cursor.execute("SELECT * from Medicine where medicine_name='" + medicine_name + "' and producer='" + producer + "' and shape='" + type_of_medicine_shape + "' ") medicine = cursor.fetchone() if medicine == None: return render_template('medicine.html', not_found='The result is not found') else: return render_template('medicine.html', data=medicine)
def finding_doctor(): if request.method == "POST": if request.form['search_string'] == '': return render_template('doctor.html', not_found="Please input email or doctor's license number to search") cursor = db.cursor() if request.form['type_of_search'] == 'email': cursor.execute("SELECT * from User where email=" + "'" + request.form['search_string'] + "'") current_data = cursor.fetchone() if current_data is None: return render_template('doctor.html', not_found='The result is not found') else: checking, final_data = finding_missing_data(cursor, current_data, 1) else: cursor.execute("SELECT * from Doctor where doctor_licensing_number=" + "'" + request.form['search_string'] + "'") current_data = cursor.fetchone() if current_data is None: return render_template('doctor.html', not_found='The result is not found') else: checking, final_data = finding_missing_data(cursor,current_data , 2) if checking == False: return render_template('doctor.html', not_found='The result is not found') return render_template('doctor.html', data=final_data) if request.method == 'GET': return render_template('doctor.html')