Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bottle import get, post, run, route, request, response
- import psycopg2, json
- from db import *
- def checkcredentials(username, password):
- cur = conn.cursor()
- cur.execute("SELECT password = crypt(%s, password) FROM users WHERE name = %s", (password, username))
- result = cur.fetchone()
- if result is not None:
- return str(result[0])
- else:
- return "false"
- @get('/login')
- def login():
- checkcredentials(request.params.username, request.params.password)
- @get('/patients')
- def getPatients():
- if checkcredentials(request.params.username, request.params.password):
- cur = conn.cursor()
- query = "SELECT * FROM patients ORDER BY lname DESC;"
- cur.execute(query)
- returnme = json.dumps(safefetchall(cur, 0))
- cur.close()
- return returnme
- response.status=403
- @post('/addpatient')
- def addPatient():
- if checkcredentials(request.params.username, request.params.password):
- cur = conn.cursor()
- query = "INSERT INTO patients(fname,lname,dob,address,city,state,country,zip,zip_plus,prim_phone,sec_phone,emerg_phone,gender) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);"
- params = (request.params.fname, request.params.lname, request.params.dob, request.params.address,
- request.params.city, request.params.state, request.params.country, request.params.zip,
- request.params.zip_plus, request.params.prim_phone, request.params.sec_phone,
- request.params.emerg_phone, request.params.gender)
- cur.execute(query, params)
- cur.close()
- response.status=201
- return
- response.status=403
- @get('/<pid:int>/basicinfo')
- def info(pid=''):
- if checkcredentials(request.params.username, request.params.password):
- cur = conn.cursor()
- query = "SELECT * FROM patient_basic_info WHERE patient_id = %s ORDER BY recorddate DESC"
- if request.params.all == 0:
- query += " LIMIT 1"
- cur.execute(query + ";", str(pid))
- returnme = json.dumps(safefetchall(cur, 1))
- cur.close()
- return returnme
- response.status=403
- @post('/<pid:int>/addbasicinfo')
- def addBasicInfo():
- if checkcredentials(request.params.username, request.params.password):
- cur = conn.cursor()
- query = "INSERT INTO patient_basic_info(patient_id, height, weight, heart_rate, systolic_pressure, diastolic_pressure, notes) VALUES(%s, %s, %s, %s, %s, %s, %s);"
- params = (request.params.patient_id, request.params.height, request.params.weight, request.params.heart_rate,
- request.params.systolic_pressure, request.params.diastolic_pressure, request.params.notes)
- cur.execute(query, params)
- cur.close()
- response.status=201
- return
- response.status=403
- @get('/<pid:int>/bloodpanel')
- def blood(pid=''):
- if checkcredentials(request.params.username, request.params.password):
- cur = conn.cursor()
- query = "SELECT * FROM blood_panel WHERE patient_id = %s ORDER BY recorddate DESC"
- if request.params.all == 0:
- query += " LIMIT 1"
- cur.execute(query + ";", str(pid))
- returnme = json.dumps(safefetchall(cur, 2))
- cur.close()
- return returnme
- response.status=403
- @post('/<pid:int>/addbloodpanel')
- def addBloodPanel():
- if checkcredentials(request.params.username, request.params.password):
- cur = conn.cursor()
- query = "INSERT INTO blood_panel(patient_id, albumin, alkaline_phosphatase, alt, ast, bun, calcium, chloride, carbon_dioxide, creatinine, glucose, potassium, sodium, bilirubin, protein)"
- + " VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);"
- params = (request.params.patient_id, request.params.albumin, request.params.alkaline_phosphatase, request.params.alt,
- request.params.ast, request.params.bun, request.params.calcium, request.params.chloride, request.params.carbon_dioxide, request.params.creatinine,
- request.params.glucose, request.params.potassium, request.params.sodium, request.params.bilirubin, request.params.protein)
- cur.execute(query, params)
- cur.close()
- response.status=201
- return
- response.status=403
- conn = psycopg2.connect(database="SHARP", user="test", password="hello", host="localhost", port="5433")
- run(host='localhost', port=8080, debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement