def add_slots(request): table = Table('slots') email = getEmail(request.session['session_key']) days = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'] if request.method == 'POST': st_time = request.POST['st_time'] end_time = request.POST['end_time'] fees = request.POST['fees'] dow = [] for d in days: string = 'weekday-' + d if string in request.POST.keys(): dow.append(d) data = table.scan(FilterExpression={}).values() items = data['Items'] l = len(str(email)) num = 0 for it in items: c = int(it['slot_id'][l:]) if (c > num): num = c num += 1 num = email + str(num) table.insertValues(values=[{ 'slot_id': num, 'doc_id': email, 'start_time': st_time, 'end_time': end_time, 'fees': fees, 'days': dow }]) print(table.scan(FilterExpression={'doc_id': email}).values()) response = redirect('/appointments/doc_slots/') return response
def confirm(request): if 'doc_id' in request.GET and 'date' in request.GET and 'slot_id' in request.GET: user_id = getEmail(request.session['session_key']) docTable = Table('doctor') result = docTable.scan(FilterExpression={'doc_id':request.GET['doc_id']}).values()['Items'][0] date = request.GET['date'] appointement_helper = Table('appointement_helper') result3 = appointement_helper.scan(FilterExpression={ 'doc_id':result['doc_id'], 'date': request.GET['date'], }).values()['Items'][0]['avilableSlots'] slot = [] for res in result3: if res['slot_id'] == request.GET['slot_id']: result3.remove(res) slot = res appointement_helper.delete(FilterExpression={'doc_id':result['doc_id'], 'date': request.GET['date'],}) appointement_helper.insertValues(values=[{ 'id':result['doc_id']+date, 'date':date, 'doc_id':result['doc_id'], 'avilableSlots':result3, }]) appointementTable = Table('appointments') appointementTable.insertValues(values=[{ 'id':"u"+user_id+'d'+result['doc_id']+'on'+date+'slot'+slot['slot_id'], 'user_id':user_id, 'doctor':result, 'slot': slot, 'date':date, }]) return render(request,'book_appointement/confirm.html',{'doc': result,'slot':slot,'date':date}) else: return render(request,'global/400.html')
def Appointemets(request): uid=getEmail(request.session['session_key']) table = Table('appointments') appointments = table.scan(FilterExpression={'user_id':uid}).values() rdict={} if appointments['Count']!=0: rdict={'appointements':appointments['Items']} return render(request,'book_appointement/pat_Appointement.html',rdict)
def dashboard(request): email = getEmail(request.session['session_key']) Date = str(date.today()) today = Date[8:10] + Date[5:7] + Date[0:4] table = Table('appointments') result = table.scan(FilterExpression={ 'date': today, 'doc_id': email }).values() return render(request, 'appointments/dashboard.html', {'app': result['Items']})
def del_slots(request): table = Table('slots') email = getEmail(request.session['session_key']) list = [] if request.method == 'POST': # print(request.POST) for key, val in request.POST.items(): if val == 'on': list.append(key) print(list) for id in list: table.delete(FilterExpression={'slot_id': id}) response = redirect('/appointments/') return response
def doc_home(request): table = Table('slots') email = getEmail(request.session['session_key']) response = table.scan(FilterExpression={'doc_id': email}).values() items = response['Items'] c = 1 for item in items: item['num'] = c item['start_time'] = str(item['start_time'][0:2]) + ":" + str( item['start_time'][2:4]) item['end_time'] = str(item['end_time'][0:2]) + ":" + str( item["end_time"][2:4]) item['fees'] = str(item['fees']) c += 1 return render(request, "appointments/doc_slots.html", {'items': items})
def appoint(request): table = Table('appointments') table2 = Table('slots') data = table.scan(FilterExpression={}).values() email = getEmail(request.session['session_key']) # print(data) # print(request.POST['slot_id']) # email = "*****@*****.**" if request.method == "POST": num = 0 items = data['Items'] for it in items: c = int(it['app_id']) if (c > num): num = c num += 1 # print(num) d = table2.scan(FilterExpression={ 'slot_id': request.POST['slot_id'] }).values() for it in d['Items']: print(it) doc_id = it['doc_id'] spec = it['spec'] start_time = it['start_time'] end_time = it['end_time'] fees = it['fees'] d1 = table.scan( FilterExpression={ 'doc_id': doc_id, 'spec': spec, 'pat_id': email, 'start_time': start_time, 'end_time': end_time }).values() if d1['Count'] == 0: table.insertValues(values=[{ 'app_id': str(num), 'doc_id': doc_id, 'spec': spec, 'pat_id': email, 'start_time': start_time, 'end_time': end_time, 'fees': fees, 'date': '30072020' }]) # return render(request, "p/", {'app_id':str(num)}) return HttpResponse("Appointment Added") else: for item in d1['Items']: sst = int(start_time) snt = int(end_time) ist = int(item['start_time']) iet = int(item['end_time']) if ist < sst < iet: return HttpResponse( "New appointment can't be created due to clashing of appointment times" ) elif ist < snt < iet: return HttpResponse( "New appointment can't be created due to clashing of appointment times" ) elif (sst == ist) & (snt == iet): return HttpResponse( "New appointment can't be created due to clashing of appointment times" ) else: table.insertValues(values=[{ 'app_id': str(num), 'doc_id': doc_id, 'spec': spec, 'pat_id': email, 'start_time': start_time, 'end_time': end_time, 'fees': fees, 'date': '30072020' }]) return HttpResponse("Appointment Added")