def referral(apptid): appt = appt_manager.search_by_id(int(apptid)) user = user_manager.get_user(current_user.get_id()) if type(user) is Provider: identity = user_manager.get_user(appt.provider_email) else: identity = user_manager.get_user(appt.patient_email) correct_identity(identity, user) specialist = user_manager.specialists() if request.method == 'POST': patient = user_manager.get_user(appt.patient_email) spec = request.form['ref_tgt'] gp = appt.provider_email msg = request.form['ref_msg'] patient.add_referral(spec, gp, msg) print(patient.referrals) print(spec) user_manager.save_data() content = {"spec": spec, "patient": patient.email, "msg": msg} return render_template('referral.html', apptid=apptid, specialist=specialist, content=content) return render_template('referral.html', apptid=apptid, specialist=specialist)
def appointment_history(): correct_identity(current_user, current_user) user = user_manager.get_user(current_user.get_id()) if type(user) is Provider: prov_view = True else: prov_view = False user.set_past_appointments() arg = 'current' if request.args.get('appt'): arg = request.args.get('appt') content = {} if arg == "current": appt = user.get_upcoming_appointments() elif arg == "past": appt = user.get_past_appointments() elif arg == "ref": appt = user.referrals.values() else: raise AppointmentError("Appointment History not Found") # content['current'] = [x.get_information() for x in cur_appt] # content['past'] = [x.get_information() for x in past_appt] # # This isn't particularly pretty now, will refactor eventually content = [x.get_information() for x in appt] if arg != "ref": for appt in content: prov = user_manager.get_user(appt['provider_email']) appt['prov_name'] = " ".join([prov.given_name, prov.surname]) patient = user_manager.get_user(appt['patient_email']) appt['patient_name'] = " ".join( [patient.given_name, patient.surname]) appt['centre_name'] = centre_manager.get_centre_from_id( appt['centre_id']).name # for appt in content['past']: # prov = user_manager.get_user(appt['provider_email']) # appt['prov_name'] = " ".join([prov.given_name, prov.surname]) # patient = user_manager.get_user(appt['patient_email']) # appt['patient_name'] = " ".join([patient.given_name, patient.surname]) # appt['centre_name'] = centre_manager.get_centre_from_id(appt['centre_id']).name return render_template('appointment_history.html', content=content, prov_view=prov_view, arg=arg)
def view_appointment(apptid): try: appt = appt_manager.search_by_id(int(apptid)) except IdentityError as e: raise e edit = False gp = False user = user_manager.get_user(current_user.get_id()) if type(user) is Provider: identity = user_manager.get_user(appt.provider_email) if appt.past is False: edit = True if user.service == "gp": gp = True else: identity = user_manager.get_user(appt.patient_email) if permissions.check_permissions(current_user.get_id(), appt.patient_email): pass elif user.email == appt.patient_email: pass elif not correct_identity(identity, user): raise IdentityError("Wrong user for Appointment") if request.method == 'POST': if request.form['notes']: appt.notes = { 'provider': current_user.get_id(), 'notes': request.form['notes'] } if request.form['meds']: appt.add_meds(request.form["meds"]) user_manager.save_data() appt_manager.save_data() content = appt.get_information() prov = user_manager.get_user(appt.provider_email) content['prov_name'] = " ".join([prov.given_name, prov.surname]) patient = user_manager.get_user(content['patient_email']) content['patient_name'] = " ".join([patient.given_name, patient.surname]) content['centre_name'] = centre_manager.get_centre_from_id( content['centre_id']).name content['meds'] = ", ".join(content['meds']) can_edit = permissions.check_permissions(current_user.get_id(), content['patient_email']) return render_template('appointment.html', content=content, edit=edit, gp=gp, has_permission=can_edit, curr_user=current_user.get_id())
def test_identity_error(patients): from model.system import correct_identity with pytest.raises(IdentityError) as error: correct_identity(patients[0], patients[1])