def update_profile(): user_id = auth.uid() data = request.get_json() if (data.get('first_name')): update.db.update_first(data.get('first_name'), user_id) if (data.get('last_name')): update.db.update_last(data.get('last_name'), user_id) if (data.get('email')): update.db.update_email(data.get('email'), user_id) if (data.get('league')): update.db.update_league(data.get('league'), user_id) if (data.get('allergies')): update.db.update_allergies(data.get('allergies'), user_id) if (data.get('pharmacy_name')): update.db.update_pharmacy_name(data.get('pharmacy_name'), user_id) if (data.get('pharmacy_address')): update.db.update_pharmacy_address(data.get('pharmacy_address'), user_id) if (data.get('pharmacy_number')): update.db.update_pharmacy_phone(data.get('pharmacy_number'), user_id) return jsonify(message="ok")
def add(medication_id, day_to_take, time_to_take, run_out_date): conn = db.conn() cursor = conn.cursor() #print(add_cmd % (auth.uid(), medication_id, day_to_take, time_to_take, run_out_date)) if time_to_take.hour >= 0 and time_to_take.hour <= 3: if day_to_take == 6: day_to_take = 0 else: day_to_take += 1 cursor.execute(add_cmd, [auth.uid(), medication_id, day_to_take, time_to_take, run_out_date] ) cursor.execute(get_id_of_add, [auth.uid(), medication_id, day_to_take, time_to_take]) notification_id = cursor.fetchall()[0] conn.commit() return notification_id
def find_med_with_cui(cui): conn = db.conn() cursor = conn.cursor(db.DictCursor) count = cursor.execute(meds_with_cui_cmd, [auth.uid(), cui]) if count == 0: return None med = cursor.fetchall()[0] return med.get("id")
def check_leagues(cui, name): conn = db.conn() cursor = conn.cursor() leagues = cursor.execute(get_user_leagues, [auth.uid()]) leagues = cursor.fetchall() if leagues[0][0] == "": return "" else: banned_cmd = """SELECT league FROM banned WHERE name like %s""" cursor.execute(banned_cmd, [name.split(' ', 1)[0]]) return cursor.fetchall()
def add(name, cui, quantity, notifications, temporary, alert_user, refill): conn = db.conn() cursor = conn.cursor() try: quantity_parsed = int(quantity) except: raise InvalidQuantity() try: temporary_parsed = int(bool(temporary)) except: raise InvalidTemporary() try: alert_user_parsed = bool(alert_user) except: raise InvalidAlertUser() notifications = [parse_notification(notif) for notif in notifications] run_out_date = calc_run_out_date(quantity_parsed, notifications, start=dt.datetime.now()) medication_id = meds.fda.get_rx(cui) side_effects = get_drug_side_effects(cui) leagues_banned_in = get_leagues_banned_in(name) cursor.execute(add_cmd, [ auth.uid(), cui, name, quantity_parsed, run_out_date.strftime('%Y-%m-%d %H:%M:%S'), temporary_parsed, medication_id, leagues_banned_in, side_effects, refill ]) cursor.execute("SELECT LAST_INSERT_ID();") get_id = cursor.fetchall() medication_notification_id = get_id[0][0] conn.commit() if alert_user: for notif in notifications: #print(medication_notification_id, notif.day, notif.time, run_out_date.strftime('%Y-%m-%d %H:%M:%S')) notification.db.add(medication_notification_id, notif.day, notif.time, run_out_date.strftime('%Y-%m-%d %H:%M:%S')) return get_id[0][0]
def check_all(): conflicts = [] conn = db.conn() cursor = conn.cursor(db.DictCursor) cursor.execute( """ SELECT id FROM user_meds WHERE user_id = %s """, [auth.uid()]) meds = cursor.fetchall() for med in meds: conflicts += check(med["id"]) return conflicts
def update_med(): user_id = auth.uid() data = request.get_json() try: med_id = data["med_id"] except KeyError as err: raise MissingDataError(err) if (data.get('name')): update.db.update_med_name(data.get('name'), med_id) if (data.get('quantity')): update.db.update_med_quantity(data.get('quantity'), med_id) if (data.get('temporary')): update.db.update_med_temporary(data.get('temporary'), med_id) return jsonify(message="ok")
def for_user(): conn = db.conn() cursor = conn.cursor(db.DictCursor) cursor.execute(for_user_cmd, [auth.uid()]) users_meds = cursor.fetchall() for user_med in users_meds: med_id = user_med.get("medication_id") count = cursor.execute(get_med_cmd, [med_id]) if count == 0: continue row = cursor.fetchone() del row["id"] user_med.update(row) return users_meds
def cal(): user_id = auth.uid() noti = notification.db.cal(user_id) return jsonify(message="ok", notifications=noti)
def side_effects(): return jsonify(message="ok", side_effects=users.db.side_effects(uid=auth.uid()))
def get_side_effects(): side_effects = users.db.get_side_effects(auth.uid()) return jsonify(side_effects=side_effects)
def delete(): users.db.delete_user(auth.uid()) return jsonify(message="ok")
def profile(): return jsonify( message="ok", profile=users.db.user_profile(auth.uid()) )