def report(request, username): context = Context(request) user = User.objects.get(username=username) patient = User_detail.objects.get(user=user) if (Report.objects.filter(patient=patient).exists()): all_report = Report.objects.filter(patient=patient) context = Context(request) context['reports'] = all_report return render(request, 'Viewreport.html', context) else: messages.add_message(request, messages.WARNING, "No report Found") return HttpResponseRedirect('/')
def gen_report(request): context = Context(request) if (request.method == "POST"): user = request.user try: doctor = Doctor_details.objects.get(user=request.user) except: messages.add_message(request, messages.WARNING, "Access Denied") return HttpResponseRedirect('/') try: un = request.POST.get('username') user = User.objects.get(username=un) patient = User_detail.objects.get(user=user) except: messages.add_message(request, messages.WARNING, "User name not registered") return HttpResponseRedirect('/reports/new/') nre = Report(doctor=doctor, patient=patient, history=request.POST.get('history'), observ=request.POST.get('observ'), dis=request.POST.get('discrip'), test=request.POST.get('test'), medic=request.POST.get('medic'), cmnt=request.POST.get('comment'), date=now_t.date()) print(type(nre)) nre.save() return HttpResponseRedirect('/') else: return render(request, 'report.html', context)
def register(request): context = Context(request) if check_grp(request.user) == True: if (request.method == 'POST'): fn = request.POST.get('firstname') ln = request.POST.get('lastname') email = request.POST.get('email') cn = request.POST.get('contact') un = fn + str(random.randrange(10, 99)) gen = request.POST.get('gender') dob = request.POST.get('dob') p1 = str(dob) p2 = str(dob) bldg = request.POST.get('bldg') adres = request.POST.get('address') if (User.objects.filter(username=un).exists()): messages.add_message(request, messages.WARNING, "username already exists") return HttpResponseRedirect('/register/') if (p1 != p2): messages.add_message(request, messages.WARNING, "password did not matched") return HttpResponseRedirect('/register/') new_user = User.objects.create_user(username=un, email=email, password=p1, first_name=fn, last_name=ln) new_user.save() details = User_detail(user=new_user, gender=gen, blood_group=bldg, contact_no=int(cn), address=adres, dob=dob) details.save() group = Group.objects.get(name='Patients') new_user.groups.add(group) send(un, email, str(dob)) # messages.add_message(request, messages.WARNING ,"Error occured in database") # return HttpResponseRedirect('/register/') messages.add_message(request, messages.WARNING, 'Successfully Registered' + un) return HttpResponseRedirect('/appointments/book') else: return render(request, 'register.html', context) else: messages.add_message(request, messages.WARNING, "Hold right there !!Accses Denied") return HttpResponseRedirect('/')
def viewreports(request): context = Context(request) if Doctor_details.objects.filter(user=request.user).exists(): if (request.method == "POST"): un = request.POST.get('username') return HttpResponseRedirect('/reports/' + str(un) + '/') else: return render(request, 'user.html', context) else: messages.add_message(request, messages.WARNING, "Accses Denied") return HttpResponseRedirect('/')
def book_appointment(request): context = Context(request) if check_grp(request.user) == True: if (request.method == 'POST'): form = AppointmentForm(request.POST) print("paased") if form.is_valid(): form.cleaned_data un = form.cleaned_data['user_name'] dn = form.cleaned_data['doctor_name'] date = request.POST.get('date') time = request.POST.get('time') comment = form.cleaned_data['Comment'] if (User.objects.filter(username=un).exists()): user = User.objects.get(username=un) patient = User_detail.objects.get(user=user) # user = User.objects.get(username = dn) # doctor = Doctor_details.objects().get(user = user) appointment = Appointments(patient=patient, doctor=dn, time=time, date=date, comment=comment) appointment.save() new_bill = Bills(patient=patient, amount=150, date=now_t.date(), time=now_t.time(), detail="Appointment Charges to") new_bill.save() patient.doctor = dn patient.save() print(patient.doctor) messages.add_message(request, messages.WARNING, "Successfully added appointment") return HttpResponseRedirect('/') else: messages.add_message(request, messages.WARNING, "Patient not registerd") return HttpResponseRedirect('/register/') else: return HttpResponseRedirect('/appointments/book/') else: form = AppointmentForm() context['form'] = form return render(request, 'appointment.html', context) else: messages.add_message(request, messages.WARNING, "Accses Denied") return HttpResponseRedirect('/')
def profile(request,username): context = Context(request) menu = {} user = User.objects.get(username = username) menu['First Name'] = user.first_name menu['Last Name'] = user.last_name menu['Email'] = user.email menu['Date_Joined'] = user.date_joined.date try: patient = User_detail.objects.get(user=user) fields = patient.__dict__ for field,value in fields.items(): if(field =='_state' or field == 'id' or field =='user_id' or field == 'doctor_id'): continue menu[field] = value except: pass try: doctor = Doctor_details.objects.get(user = user) fields = doctor.__dict__ for field,value in fields.items(): if(field =='_state' or field == 'id' or field =='user_id'): continue menu[field] = value except: pass if(request.user.username == username): # print(menu) context['menu'] = menu return render(request,'profile.html',context) try: doctor = Doctor_details.objects.get(user = request.user) # print(menu) context['menu'] = menu return render(request,'profile.html',context) except: messages.add_message(request, messages.WARNING ,"Accses Denied") return HttpResponseRedirect('/')
def view_appointments(request): context = Context(request) try: doctor = Doctor_details.objects.get(user=request.user) except: messages.add_message(request, messages.WARNING, "Accses Denied") return HttpResponseRedirect('/') all_appointment = Appointments.objects.filter(doctor=doctor) up_list = [] past_list = [] list_appointments = [] for appoint in all_appointment: temp_list = {} temp_list['patient'] = str(appoint.patient) temp_list['date'] = str(appoint.date) temp_list['time'] = str(appoint.time) temp_list['comment'] = str(appoint.comment) if (appoint.date < now_t.date()): past_list.append(temp_list) elif (appoint.date == now_t.date()): if (appoint.time < now_t.time()): past_list.append(temp_list) else: up_list.append(temp_list) else: up_list.append(temp_list) list_appointments.append(temp_list) # print(up_list ," up coming list is -----1-1-1-") # print(past_list) context['up'] = up_list context['pre'] = past_list context['now_t'] = now_t return render(request, 'view.html', context)