def destroy(): online_user = get_jwt_identity() user = User.get_or_none(User.id == online_user['id']) if "admin" not in user.role: return jsonify({ "message": "401 Unauthorized (Only admin is allowed)", "status": "fail" }) id = request.json.get("appointment_id") appointment = Appointment.get_or_none(Appointment.id == id) if appointment: if appointment.record: return jsonify({ "message": "An appointment with record is not deleteable.", "status": "fail" }) else: if appointment.delete_instance(): return jsonify({ "message": "Successfully deleted appointment.", "status": "success" }) else: return jsonify({ "message": "Couldn't delete appointment.", "status": "fail" }) else: return jsonify({ "message": "No such appointment exists.", "status": "fail" })
def get_zoom_url(): import json from zoomus import ZoomClient from zoomus.components import meeting from app import app client = ZoomClient(app.config.get('ZOOM_API_KEY'), app.config.get('ZOOM_API_SECRET')) user_list_response = client.user.list() user_list = json.loads(user_list_response.content) for user in user_list['users']: user_id = user['id'] print(json.loads(client.meeting.list(user_id=user_id).content)) new_meeting = client.meeting.create(user_id=user_id).json() join_url = new_meeting['join_url'] id = request.args.get('appointment_id') appointment = Appointment.get_or_none(Appointment.id == id) appointment.zoom_url = join_url appointment.start_datetime = appointment.start_datetime.strftime( "%Y-%m-%d %H:%M:%S") appointment.end_datetime = appointment.end_datetime.strftime( "%Y-%m-%d %H:%M:%S") if appointment.save(): return join_url else: return "fail"
def search(): id = request.args.get("appointment_id") appointment = Appointment.get_or_none(Appointment.id == id) if appointment: if appointment.zoom_url: zoom_link = a.zoom_url else: zoom_link = None return jsonify({ "appointment_id": appointment.id, "doctor_name": appointment.doctor.name, "patient_name": appointment.patient.name, "doctor_ic": appointment.doctor.ic_number, "patient_ic": appointment.patient.ic_number, "appointment_start": appointment.start_datetime.strftime("%Y-%m-%d %H:%M:%S"), "appointment_end": appointment.end_datetime.strftime("%Y-%m-%d %H:%M:%S"), "zoom_link": zoom_link }) else: return jsonify({"message": "Appointment not found.", "status": "fail"})
def edit(): online_user = get_jwt_identity() user = User.get_or_none(User.id == online_user['id']) if "admin" not in user.role: return jsonify({ "message": "401 Unauthorized (Only admin is allowed)", "status": "fail" }) id = request.json.get("appointment_id") start_datetime = request.json.get("start_datetime") end_datetime = request.json.get("end_datetime") doctor_ic = request.json.get("doctor_ic") patient_ic = request.json.get("patient_ic") appointment = Appointment.get_or_none(Appointment.id == id) if appointment: start_datetime = request.json.get("start_datetime") end_datetime = request.json.get("end_datetime") doctor_ic = request.json.get("doctor_ic") patient_ic = request.json.get("patient_ic") doctor = User.get_or_none(User.ic_number == doctor_ic) patient = User.get_or_none(User.ic_number == patient_ic) if doctor == None or patient == None: return jsonify({ "message": "Patient or doctor not found", "status": "fail" }) appointment.doctor = doctor appointment.patient = patient appointment.start_datetime = start_datetime appointment.end_datetime = end_datetime if appointment.save(): response = { "message": "successfully changed appointment's info!", "status": "success", "patient_name": appointment.patient.name, "doctor_name": appointment.doctor.name, "patient_ic": appointment.patient.ic_number, "doctor_ic": appointment.doctor.ic_number, "start_datetime": appointment.start_datetime, "end_datetime": appointment.end_datetime } else: response = appointment.error() else: response = {"message": "Appointment not found.", "status": "fail"} return jsonify(response)
def create(): appointment_id = request.form.get("appointment_id") a = Appointment.get_or_none(Appointment.id == appointment_id) if a.record: return jsonify({ "message": "This appointment already has an existing record.", "status": "fail" }) else: pass cholestrol_level = request.form.get("cholestrol_level") sugar_level = request.form.get("sugar_level") systolic_blood_pressure = request.form.get("systolic_blood_pressure") diastolic_blood_pressure = request.form.get("diastolic_blood_pressure") online_user = get_jwt_identity() user = User.get_or_none(User.id == online_user['id']) if (user) and ("patient" in user.role): #need to be updated if allow guardian to create record patient_record = Record(cholestrol_level=cholestrol_level, sugar_level=sugar_level, systolic_blood_pressure=systolic_blood_pressure, diastolic_blood_pressure=diastolic_blood_pressure, appointment_id=appointment_id) if patient_record.save(): response = { "message": f"Successfully created record.", "status": "success", "cholestrol level" : patient_record.cholestrol_level, "sugar level" : patient_record.sugar_level, "systolic_blood_pressure" : patient_record.systolic_blood_pressure, "diastolic_blood_pressure" : patient_record.diastolic_blood_pressure, "appointment_id": patient_record.appointment_id } else: return jsonify({ "message": "Add record failed, please try again", "status": "fail" }) # Image Upload Start images = [] for i in range(int(request.form.get('image_count'))): image = request.files['image_files' + str(i)] caption = request.form.get('caption' + str(i)) if 'image' not in image.mimetype: patient_record.delete_instance() return jsonify({ "message": "One or more of the uploaded files is not an image. Please try again", "status": "fail" }) else: file_extension = image.mimetype file_extension = file_extension.replace('image/', '.') image.filename = str(datetime.now()) + file_extension image.filename = secure_filename(image.filename) image_url = upload_file_to_s3(image, user.ic_number) upload_image = Patient_Photo(record_id=patient_record.id, image_url=image_url, caption=caption) if upload_image.save(): images.append({ "image_url": upload_image.full_image_url, "caption": caption }) else: patient_record.delete_instance() return jsonify({ "message": "Image upload failed, please try again", "status": "fail" }) response["images"] = images else: response = { "message": "User not found/ Only patient is allowed to create record.", "status": "fail" } return jsonify(response)