def patient(ptid): '''Works ''' if request.method == 'GET': patient_info = fdb.query_db_get_one( 'SELECT * FROM ' + _PATIENTS_TABLE + ' WHERE id={0}'.format(_PLACEHOLDER), (ptid, )) #retrieve measurements query = 'SELECT * FROM ' + _MEASUREMENTS_TABLE + ' WHERE patient_id={0}'.format( _PLACEHOLDER) # this IS good enough@ #no need to join - keeping the patient and measurements dictionary separate, makes it easier/more intuitive to write the template code #query='SELECT * FROM '+_MEASUREMENTS_TABLE+' as v JOIN (SELECT * FROM Patients WHERE id={0}) as p ON v.patient_id=p.id'.format(_PLACEHOLDER) patient_measurements = fdb.query_db_get_all(query, (ptid, )) return render_template('patient.html', patient=patient_info, measurements=patient_measurements) elif request.method == 'POST': systolic = request.form['systolic'] diastolic = request.form['diastolic'] pulse = request.form['pulse'] fdb.query_db_change( 'INSERT INTO ' + _MEASUREMENTS_TABLE + '(systolic, diastolic, pulse, patient_id) VALUES ({0}, {0}, {0}, {0})' .format(_PLACEHOLDER), (systolic, diastolic, pulse, ptid)) return redirect(url_for('patient', ptid=ptid))
def patients(): '''Works''' if request.method == 'GET': patient_list = fdb.query_db_get_all('SELECT * FROM ' + _PATIENTS_TABLE) print(patient_list) return jsonify(patient_list) elif request.method == 'POST': fName = request.form['first_name'] lName = request.form['last_name'] Name = fName + " " + lName eMail = request.form['e_mail'] _date = request.form['date'] address = request.form['address'] healthcardno = request.form['healthcardno'] p1 = -1 p2 = -1 p3 = -1 p4 = -1 result = fdb.query_db_change( 'INSERT INTO ' + _PATIENTS_TABLE + '(firstname, lastname, name, email, date_, address, healthcardno, p1, p2, p3, p4) VALUES ({0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0})' .format(_PLACEHOLDER), (fName, lName, Name, eMail, _date, address, healthcardno, p1, p2, p3, p4)) if result == None: print("Could not insert new record into", _PATIENTS_TABLE) return render_template('p1.html', ptid=result)
def providers(): '''Works''' if request.method == 'GET': #provider_list = fdb.query_db_get_all('SELECT * FROM '+_PROVIDERS_TABLE) #print(provider_list) #return jsonify(provider_list) return render_template('add_provider.html') elif request.method == 'POST': fName = request.form['first_name'] lName = request.form['last_name'] Name = fName + " " + lName eMail = request.form['e_mail'] result = fdb.query_db_change( 'INSERT INTO ' + _PROVIDERS_TABLE + '(firstname, lastname, name, email) VALUES ({0}, {0}, {0}, {0})'. format(_PLACEHOLDER), (fName, lName, Name, eMail)) if result == None: print("Could not insert new record into", _PROVIDERS_TABLE) #return render_template('p1.html', ptid=result) return redirect(url_for('providers'))
def add_user(username, password, email): fdb.query_db_change( 'INSERT INTO Users (email_address, username, password) VALUES({0}, {0}, {0})' .format(_PLACEHOLDER), (email, username, generate_password_hash(password)))
def p4_update(ptid, ptsel): query = 'UPDATE ' + _PATIENTS_TABLE + ' SET p4=? WHERE id=?' args = (ptsel, ptid) fdb.query_db_change(query, args) return jsonify(ptid)