def update_time(): token = extract_auth_token(request) user_id = None if (token == None): abort(403) try: user_id = decode_token(token) except: abort(403) # update the user appt = request.json['id'] appt = Appointment.query.filter_by(id=appt).first() new_time = datetime.strptime(request.json['appointment_time'], '%Y-%m-%dT%H:%M') user_times = Appointment.query.filter_by( appointment_time=new_time).filter_by( patient_id=appt.patient_id).first() if (user_times != None): return "patient has a conflict" doc_times = Appointment.query.filter_by( appointment_time=new_time).filter_by( doctor_name=appt.doctor_name).first() if (doc_times != None): return "doctor has a conflict" appt.appointment_time = new_time db.session.commit() return jsonify(appointment_schema.dump(appt))
def book_appointment(): token = extract_auth_token(request) user_id = None if (token == None): abort(403) try: user_id = decode_token(token) except: abort(403) new_time = datetime.strptime(request.json['appointment_time'], '%Y-%m-%dT%H:%M') user_times = Appointment.query.filter_by( appointment_time=new_time).filter_by(patient_id=user_id).first() doc_times = Appointment.query.filter_by( appointment_time=new_time).filter_by( doctor_name=request.json['doctor_name']).first() if (doc_times != None): return "doctor has a conflict" if (user_times != None): return "patient has a conflict" doctor_name = request.json["doctor_name"] patient_id = user_id patient_name = User.query.filter_by(id=user_id).first().user_name appointment_time = request.json["appointment_time"] appointment_description = request.json["appointment_description"] appo = Appointment(doctor_name, patient_id, appointment_time, appointment_description, patient_name) db.session.add(appo) db.session.commit() return jsonify(appointment_schema.dump(appo))
def read_user(username): token = extract_auth_token(request) if token is None: abort(401) user = None try: user_id = decode_token(token) if user_id is None: abort(401, "You are not logged in") user = User.query.filter_by(id=user_id).first() user_to_view = User.query.filter_by(user_name=username).first() if user_to_view is None: abort(404) # Admins and Drs can view anyone, normal users cannot if not user.user_name == "admin" and not user.is_doctor and not user_to_view.is_doctor: abort(401, "You cannot view this profile") except Exception as e: print(e) abort(500) return jsonify(user_schema.dump(user))
def appointment_reports(): token = extract_auth_token(request) user_id = None if token is not None: try: user_id = decode_token(token) except (jwt.ExpiredSignatureError, jwt.InvalidTokenError): abort(403) report = Report.query.filter_by(appointment_id=request.json['appointment_id']).first() return jsonify(report_schema.dump(report))
def all_reports(): token = extract_auth_token(request) user_id = None if token is not None: try: user_id = decode_token(token) except (jwt.ExpiredSignatureError, jwt.InvalidTokenError): abort(403) reports = Report.query.all() return jsonify(reports_schema.dump(reports))
def delete_report(): token = extract_auth_token(request) user_id = None if token is not None: try: user_id = decode_token(token) except (jwt.ExpiredSignatureError, jwt.InvalidTokenError): abort(403) report = Report.query.filter_by(appointment_id=request.json['appointment_id']).first() db.session.delete(report) db.session.commit()
def update_appt(): # check if user is logged in token = extract_auth_token(request) user_id = None if (token == None): abort(403) try: user_id = decode_token(token) except: abort(403) # update the user appt = request.json['id'] appt = Appointment.query.filter_by(id=appt).first() appt.appointment_description = request.json["appointment_description"] db.session.commit() return jsonify(appointment_schema.dump(appt))
def getDrsApts(): token = extract_auth_token(request) user_id = None if token == None: abort(403) try: user_id = decode_token(token) except: abort(403) print(user_id) ar = Appointment.query.filter_by(doctor_name=User.query.filter_by( id=user_id).first().user_name).all() ka = appointments_schema.dump(ar) newlist = sorted(ka, key=lambda k: k['appointment_time']) ret = jsonify(newlist) return ret
def read_profile(): token = extract_auth_token(request) if token is None: abort(401) user = None try: user_id = decode_token(token) user = User.query.filter_by(id=user_id).first() if user is None: abort(404) except Exception as e: print(e) abort(500) return jsonify(user_schema.dump(user))
def delete_appt(): # check if user is logged in token = extract_auth_token(request) user_id = None if (token == None): abort(403) try: user_id = decode_token(token) except: abort(403) # update the user appt = request.json['id'] appt = Appointment.query.filter_by(id=appt).first() db.session.delete(appt) db.session.commit() return jsonify("Appointment Deleted")
def change_report_description(): token = extract_auth_token(request) user_id = None if token is not None: try: user_id = decode_token(token) except (jwt.ExpiredSignatureError, jwt.InvalidTokenError): abort(403) user = User.query.filter_by(id=user_id).first() if not user.is_doctor: abort(403) report = Report.query.filter_by(appointment_id=request.json['appointment_id']).first() report.description = request.json['description'] db.session.commit() return jsonify(report_schema.dump(report))
def doctor_appointments(): token = extract_auth_token(request) if (token == None): abort(403) try: user_id = decode_token(token) except: abort(403) if (len( User.query.filter_by(user_name=request.json['doctor_name'], is_doctor=True).all()) == 0): abort(403) appt = Appointment.query.filter_by( doctor_name=request.json['doctor_name']).all() if (appt == None): return "there are no appointments for this name" ka = appointments_schema.dump(appt) print(ka) newlist = sorted(ka, key=lambda k: k['appointment_time']) # sort(k) ret = jsonify(newlist) return ret