Exemplo n.º 1
0
def addCalendar():
    """
    add a calendar for doctor
    :return: json
    """
    try:
        postData = request.json
        calendarData = postData['calendar']

        if calendarData['customer_id'] is None:
            raise Exception('Invalid Parameters')

        if calendarData['summary'] is None:
            raise Exception('Invalid Parameters')
        if calendarData['description'] is None:
            raise Exception('Invalid Parameters')
        if calendarData['location'] is None:
            raise Exception('Invalid Parameters')
        if calendarData['timezone'] is None:
            raise Exception('Invalid Parameters')

        # get Doctor
        doctor = Doctor({})
        boolean, doctorData = doctor.getOneDoctorById(
            calendarData['customer_id'])
        if not boolean:
            raise Exception('Doctor is not exists')
        else:
            if doctorData['calendar_id']:
                return make_response(
                    jsonify({
                        'code': 1,
                        'msg': 'Successfully Added!',
                        'data': {
                            'doctor_id': doctorData['id'],
                            'calendar_id': doctorData['calendar_id'],
                        }
                    }), 201)
        res, id = addSecondaryCalendar(calendarData['summary'],
                                       calendarData['description'],
                                       calendarData['location'],
                                       calendarData['timezone'])
        if res:
            # store id to database
            updateData = {'calendar_id': id}
            doctor.updateSchema(doctorData['id'], updateData)
            return make_response(
                jsonify({
                    'code': 1,
                    'msg': 'Successfully Added!',
                    'data': {
                        'doctor_id': doctorData['id'],
                        'calendar_id': id,
                    }
                }), 201)
        else:
            raise id
    except Exception as e:
        return make_response(jsonify({'code': -1, 'msg': str(e)}), 400)
Exemplo n.º 2
0
def register():
    """
    add a new doctor
    :return: json
    """
    try:
        doctor = Doctor(request.json['doctor'])
        doctor.addDoctor()
        return make_response(
            jsonify({
                'code': 1,
                'msg': 'Successfully Created!'
            }), 201)
    except Exception as e:
        return make_response(jsonify({'code': -1, 'msg': str(e)}), 400)
Exemplo n.º 3
0
def getDoctors():
    """
    get all doctors
    :return: json
    """
    try:
        doctor = Doctor({})
        results = doctor.getAllDoctors()
        return make_response(
            jsonify({
                'code': 1,
                'msg': 'Successfully Fetched!',
                'data': results
            }), 201)
    except Exception as e:
        return make_response(jsonify({'code': -1, 'msg': str(e)}), 400)
Exemplo n.º 4
0
def getOneDoctor(doctor_id):
    """
    get one doctor
    :param doctor_id: doctor id
    :return: json
    """
    try:
        doctor = Doctor({})
        results, data = doctor.getOneDoctorById(doctor_id)
        return make_response(
            jsonify({
                'code': 1,
                'msg': 'Successfully Fetched!',
                'data': data
            }), 201)
    except Exception as e:
        return make_response(jsonify({'code': -1, 'msg': str(e)}), 400)
Exemplo n.º 5
0
def getAppointmentsGroupByDoctorAndStartDate():
    """
    get statistics data
    :return:  json
    """
    appointment = Appointment()
    doctor = Doctor({})
    data = appointment.getAppointmentsGroupByDoctorAndStartDate()
    for i in range(len(data)):
        for j in range(len(data[i]['appointments'])):
            did = data[i]['appointments'][j]['doctor_id']
            res, da = doctor.getOneDoctorById(did)
            data[i]['appointments'][j]['doctor_name'] = da['name']
    data = assemblyData(data)
    return make_response(
        jsonify({
            'code': 1,
            'msg': 'Successfully Fetched!',
            'data': data
        }), 201)
Exemplo n.º 6
0
def login():
    """
    sign in system as a doctor
    :return: json
    """
    try:
        doctor = Doctor(request.json['doctor'])
        res, data = doctor.login()
        if res:
            return make_response(
                jsonify({
                    'code': 1,
                    'msg': 'Successfully Signed In!',
                    'data': data
                }), 201)
        else:
            return make_response(
                jsonify({
                    'code': -1,
                    'msg': 'Username or Password is invalid'
                }), 400)
    except Exception as e:
        return make_response(jsonify({'code': -1, 'msg': str(e)}), 400)
Exemplo n.º 7
0
def getAppointments(patient_id):
    """
    get appointments by patient id
    :param patient_id: patient id
    :return: json
    """
    try:
        if patient_id is None:
            raise Exception('Invalid Parameters')

        appointment = Appointment({})
        ds = Doctor({})
        results, data = appointment.getAllAppointmentByPatientId(patient_id, ds)
        if results :
            return make_response(jsonify({'code': 1, 'msg': 'Successfully Fetched!', 'data': data}), 201)
        else:
            raise data
    except Exception as e:
        return make_response(jsonify({'code': -1, 'msg': str(e)}), 400)