def check_guardian(): input = request.args.get("guardian_id") # guardian req: role = patient or guardian user = User.get_or_none(User.ic_number == input) if user: role_list = UserRole.select().where(UserRole.user_id == user.id) # select all existing role(s) role_id_list = [] for r in role_list: role_id_list.append(r.role_id) if 1 in role_id_list or 2 in role_id_list: response = { "valid": True, "name": user.name } else: response = { "valid": False, "message": "User does not qualify to be a guardian" } else: response = { "valid": False, "message": "User not exist" } return jsonify(response)
def role_id(self): from models.user_role import UserRole from models.role import Role role_list = UserRole.select().where(UserRole.user == self) role_id_list = [] for r in role_list: role_id_list.append(str(r.role_id)) return role_id_list #["1", "2"]
def check_patient(): input = request.args.get("patient_ic") patient = User.get_or_none(User.ic_number == input) if patient: role_list = UserRole.select().where(UserRole.user_id == patient.id) role_id_list = [] for r in role_list: role_id_list.append(r.role_id) if 1 in role_id_list: response = { "is_patient": True, "name": patient.name } else: response = { "is_patient": False } else: response = { "valid": False, "message": "User not exist" } return jsonify(response)
def check_doctor(): input = request.args.get("doctor_ic") doctor = User.get_or_none(User.ic_number == input) if doctor: role_list = UserRole.select().where(UserRole.user_id == doctor.id) role_id_list = [] for r in role_list: role_id_list.append(r.role_id) if 3 in role_id_list: response = { "is_doctor": True, "name": doctor.name } else: response = { "is_doctor": False } else: response = { "valid": False, "message": "User not exist" } return jsonify(response)