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)
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)
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)