예제 #1
0
 def get(cls, patient_id):
     if get_jwt_claims()["type"] != "patient":
         patient = PatientModel.find_by_id(patient_id)
         if patient:
             return patient.json_with_info()
         return {"message": "User not found"}, 404
     return {"message": "You have to be an admin or doctor"}
예제 #2
0
    def get(cls):
        identity = get_jwt_identity()
        claims = get_jwt_claims()

        if claims["type"] == "doctor":
            doctor_appointments = DoctorModel.find_by_id(identity).appointments

            doctorapp = [
                appointment.json() for appointment in doctor_appointments
            ]
            return doctorapp, 200

        elif claims["type"] == "patient":
            patient_appointments = PatientModel.find_by_id(
                identity).appointments

            patientapp = [
                appointment.json() for appointment in patient_appointments
            ]
            return patientapp

        else:
            appointments = AppointmentModel.find_all()
            appointments_list = [
                appointment.json() for appointment in appointments
            ]
            return appointments_list, 200
예제 #3
0
 def delete(cls, patient_id):
     if get_jwt_claims()["type"] == "admin":
         patient = PatientModel.find_by_id(patient_id)
         if patient:
             patient.delete_from_db()
             return {"message": "User deleted"}, 200
         return {"message": "User not found"}, 404
     return {"message": "Admin authorization required."}
예제 #4
0
    def post(self, patient_id):

        if get_jwt_claims()["type"] == "patient":
            {"message": "Invalid authorization"}, 401
        if not PatientModel.find_by_id(patient_id):
            return {"message": "A patient with this id does not exist"}, 404

        data = request.files
        print(request.files)
        if type(data["image"]) != FileStorage:

            return {"message": "Invalid data."}
        image_path = image_helper.save_image(data["image"],
                                             folder=f"patient_{patient_id}")
        basename = image_helper.get_basename(image_path)
        return {"message": "image uploaded"}, 201
예제 #5
0
 def get(self, patient_id):
     if get_jwt_claims()["type"] == "patient":
         return {
             "message":
             "Invalid authorization: you must be a doctor or an admin."
         }, 401
     if not PatientModel.find_by_id(patient_id):
         return {"message": "A patient with this id does not exist"}
     folder = os.getcwd()
     dirs = os.listdir(f"{folder}/static/images/patient_{patient_id}")
     file_list = []
     for file in dirs:
         file_list.append({
             "image":
             f"http://localhost:5000/static/images/patient_{patient_id}/{file}"
         })
     return file_list
예제 #6
0
    def post(cls):
        claims = get_jwt_claims()
        if claims["type"] != "patient":
            return {"message": "Access denied"}

        data = cls.appointment_parser.parse_args()
        identity = get_jwt_identity()

        if data["date"].isspace():
            return {"message": "One of the inputs is empty"}, 400

        data["patient_id"] = identity

        data['patient_username'] = PatientModel.find_by_id(identity).username

        data["doctor_id"] = int(data["doctor_id"])

        data['doctor_username'] = DoctorModel.find_by_id(
            data['doctor_id']).username

        doctor = DoctorModel.find_by_id(data["doctor_id"])
        if not doctor:
            return {"message": "Doctor not found"}, 404

        data["created_at"] = datetime.now().date()
        y1, m1, d1 = [int(x) for x in data["date"].split("-")]

        app_date = datetime(y1, m1, d1).date()

        if app_date < data["created_at"]:
            return {"message": "Invalid date"}

        apps_date = AppointmentModel.find_by_date(app_date)

        for app in apps_date:
            if app.patient_id == identity:
                return {
                    "message": "Appointment already exists at the same date"
                }

        AppointmentModel.main(app_date)
        appointment = AppointmentModel(**data)
        appointment.save_to_db()

        return {"message": "Appointment created successfully."}, 201
예제 #7
0
 def delete(self, patient_id):
     if get_jwt_claims()["type"] != "admin":
         return {
             "message": "Invalid authorization, you have to be an admin."
         }, 401
     if not PatientModel.find_by_id(patient_id):
         return {"message": "A patient with this id does not exist"}, 404
     filename = request.args.get("filename")
     folder = os.getcwd()
     dirs = os.listdir(f"{folder}/static/images/patient_{patient_id}")
     for file in dirs:
         if filename == file:
             os.remove(
                 image_helper.get_path(
                     file,
                     folder=f"{folder}/static/images/patient_{patient_id}"))
             return {"message": "file deleted"}
     return {"message": "file not found"}, 404
예제 #8
0
 def parent_id_exists(path_id):
     """Check if patient with id=path_id exists in the DB"""
     if not PatientModel.find_by_id(path_id):
         raise ValidationError(
             'Patient with id={} does not exist.'.format(path_id))