Ejemplo n.º 1
0
def create_doctor():
    """Creates a doctor
    :return: a success message
    """
    details = json.loads(request.data)

    doctor = Doctor(
        first_name=details["first_name"],
        last_name=details["last_name"]
    )

    doctor.save()
    return make_response(jsonify({"message": "Doctor added successfully"}), 201)
    def get(self):

        if connection is None:
            return {'message': 'No Connection'}, HTTPStatus.SERVICE_UNAVAILABLE

        data = []

        with connection.cursor() as cur:
            cur.execute('select * from doctor')
            records = cur.fetchall()

            if len(records) == 0:

                return {'message': "Not Found"}, HTTPStatus.NOT_FOUND

            for row in records:
                doctor = Doctor(*list(row))
                data.append(doctor.data)

        return {'data': data}, HTTPStatus.OK
    def get(self, specialization):

        data = []
        if connection is None:
            return {'message': 'No Connection'}, HTTPStatus.SERVICE_UNAVAILABLE

        data = []

        with connection.cursor() as cur:
            cur.callproc("doctor_pkg.read_doctor_specialization", [
                specialization,
            ])
            records = get_listformat(cur)

            if records is None:
                return {'message': "Not Found"}, HTTPStatus.NOT_FOUND

            for row in records:
                doctor = Doctor(*list(row))
                data.append(doctor.data)

        return {'data': data}, HTTPStatus.OK
    def get(self, doctor_id):

        doctor = None
        if connection is None:
            return {'message': 'No Connection'}, HTTPStatus.SERVICE_UNAVAILABLE

        data = []

        with connection.cursor() as cur:
            # cur.execute('select * from doctor where doctor_id = :id',{'id':doctor_id})
            cur.callproc("doctor_pkg.read_doctor_id", [
                doctor_id,
            ])

            record = get_listformat(cur)

            if record is None:
                return {'message': "Not Found"}, HTTPStatus.NOT_FOUND
            else:
                [record] = record
                doctor = Doctor(*record)

        return {'data': doctor.data}, HTTPStatus.OK