コード例 #1
0
 def get(self):
     return {
         'appointments': [
             appoint.json() for appoint in AppointmentModel.find_by_user_id(
                 current_identity.first().id).all()
         ]
     }
コード例 #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(self):
        data = Appointment.parser.parse_args()
        appointment = AppointmentModel.find_by_app_id_and_user_id(
            data['id'],
            current_identity.first().id).first()
        if appointment is not None:
            appointment.delete_from_db()

        return {'message': 'appointment is deleted'}
コード例 #4
0
    def post(self):
        data = Appointment.parser.parse_args()

        logging.debug('name is in is {}'.format('name' in data))

        if ('name' not in data) or ('description' not in data) or (
                'start' not in data) or ('end' not in data):
            return {'message': 'invalid json sent in body'}, 400

        appoint = AppointmentModel(data['name'], data['description'],
                                   data['start'], data['end'],
                                   current_identity.first().id)
        try:
            appoint.save_to_db()
        except:
            return {
                'message': 'error occurred while inserting appointment'
            }, 500
        return appoint.json(), 201
コード例 #5
0
    def delete(cls, app_id):
        claims = get_jwt_claims()
        if claims["type"] != "admin":
            return {"message": "access denied"}

        app = AppointmentModel.find_by_id(app_id)
        if not app:
            return {"message": "Appointment not found"}, 404
        app.delete_from_db()
        return {"message": "Appointment deleted"}
コード例 #6
0
 def post(cls, app_id):
     data = cls.examination_parser.parse_args()
     if data["diagnosis"].isspace() or data["prescription"].isspace():
         return {"message": "One of the inputs is empty"}, 400
     if get_jwt_claims()["type"] == "doctor":
         appointment = AppointmentModel.find_by_id(app_id)
         if appointment:
             examination = ExaminationModel(**data, appointment_id=app_id)
             examination.save_to_db()
             return {"message": "Added Successfully."}, 200
         else:
             return {"message": "No appointment with this id exists"}, 404
     return {
         "message": "Authorization required: You must be a doctor."
     }, 401
コード例 #7
0
    def put(self):
        data = Appointment.parser.parse_args()
        appoint = AppointmentModel.find_by_app_id_and_user_id(
            data['id'],
            current_identity.first().id).first()

        if 'name' not in data or 'description' not in data or 'start' not in data or 'end' not in data:
            return {'message': 'invalid json sent in body'}, 400

        if appoint is None:
            appoint = AppointmentModel(data['name'], data['description'],
                                       data['start'], data['end'],
                                       current_identity.first().id)
        else:
            appoint.update(data['name'], data['description'], data['start'],
                           data['end'])
        try:
            appoint.save_to_db()
        except:
            return {'message': 'error occurred while saving appointment'}, 500
        return appoint.json()
コード例 #8
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