def record(self): from models.record import Record from models.patient_photo import Patient_Photo r = Record.get_or_none(Record.appointment_id == self.id) if r: result = { "record_id": r.id, "appointment_id": r.appointment_id, "report": r.report, "prescription": r.prescription, "payment_amount": str(r.payment_amount), "paid": r.paid, "cholestrol_level": str(float(r.cholestrol_level)), "sugar_level": str(float(r.sugar_level)), "systolic_blood_pressure": str(float(r.systolic_blood_pressure)), "diastolic_blood_pressure": str(float(r.diastolic_blood_pressure)), "doctor_name": r.appointment.doctor.name, "doctor_ic": r.appointment.doctor.ic_number, "patient_name": r.appointment.patient.name, "patient_ic": r.appointment.patient.ic_number, "record_photo": r.photo } else: result = None return result
def search(): id = request.args.get("record_id") record = Record.get_or_none(Record.id == id) if record: return jsonify({ "record_id": record.id, "appointment_id": record.appointment_id, "report": record.report, "prescription": record.prescription, "payment_amount": str(record.payment_amount), "paid": record.paid, "cholestrol_level": str(float(record.cholestrol_level)), "sugar_level": str(float(record.sugar_level)), "systolic_blood_pressure": str(float(record.systolic_blood_pressure)), "diastolic_blood_pressure": str(float(record.diastolic_blood_pressure)), "doctor_name": record.appointment.doctor.name, "doctor_ic": record.appointment.doctor.ic_number, "patient_name": record.appointment.patient.name, "patient_ic": record.appointment.patient.ic_number, "record_photo": record.photo }) else: return jsonify({ "message": "There is no such record.", "status": "fail" })
def edit(): online_user = get_jwt_identity() user = User.get_or_none(User.id == online_user['id']) if user: update_record = Record.get_or_none(Record.id == request.json.get("record_id")) if update_record: if (user == update_record.appointment.doctor): update_record.report = request.json.get("report") update_record.prescription = request.json.get("prescription") if update_record.save(): response = { "message": "Updated record successfully", "status": "success", "report": update_record.report, "prescription": update_record.prescription } else: response = { "message": "Record not saved", "status": "fail" } elif ("admin" in user.role): update_record.payment_amount = request.json.get("payment_amount") if update_record.save(): response = { "message": "Updated record successfully", "status": "success", "updated_payment_amount": update_record.payment_amount } else: response = { "message": "Record not saved", "status": "fail" } else: response = { "message": "401 Unauthorized (Only the doctor or admin is allowed.)", "status": "fail" } else: response = { "message": "Record not found", "status": "fail" } else: response = { "message": "User does not exist", "status": "fail" } return jsonify(response)
def create(): amount = request.json.get("amount_paid") nonce_from_the_client = request.json.get("payment_method_nonce") result = transact({ "amount": amount, "payment_method_nonce": nonce_from_the_client, "options": { "submit_for_settlement": True } }) if result.is_success or result.transaction: record = Record.get_or_none(Record.id == request.json.get("record_id")) record.paid = True if record.save(): response = {"message": "payment successful", "status": "success"} else: for x in result.errors.deep_errors: flash('Error: %s: %s' % (x.code, x.message)) return jsonify(response)
def follow_status(self, following): from models.record import Record return Record.get_or_none(Record.follower == self.id, Record.following == following.id)