-
Notifications
You must be signed in to change notification settings - Fork 517
/
Copy pathviews.py
848 lines (642 loc) · 31.7 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
from django.shortcuts import render,redirect,reverse
from . import forms,models
from django.db.models import Sum
from django.contrib.auth.models import Group
from django.http import HttpResponseRedirect
from django.core.mail import send_mail
from django.contrib.auth.decorators import login_required,user_passes_test
from datetime import datetime,timedelta,date
from django.conf import settings
from django.db.models import Q
# Create your views here.
def home_view(request):
if request.user.is_authenticated:
return HttpResponseRedirect('afterlogin')
return render(request,'hospital/index.html')
#for showing signup/login button for admin(by sumit)
def adminclick_view(request):
if request.user.is_authenticated:
return HttpResponseRedirect('afterlogin')
return render(request,'hospital/adminclick.html')
#for showing signup/login button for doctor(by sumit)
def doctorclick_view(request):
if request.user.is_authenticated:
return HttpResponseRedirect('afterlogin')
return render(request,'hospital/doctorclick.html')
#for showing signup/login button for patient(by sumit)
def patientclick_view(request):
if request.user.is_authenticated:
return HttpResponseRedirect('afterlogin')
return render(request,'hospital/patientclick.html')
def admin_signup_view(request):
form=forms.AdminSigupForm()
if request.method=='POST':
form=forms.AdminSigupForm(request.POST)
if form.is_valid():
user=form.save()
user.set_password(user.password)
user.save()
my_admin_group = Group.objects.get_or_create(name='ADMIN')
my_admin_group[0].user_set.add(user)
return HttpResponseRedirect('adminlogin')
return render(request,'hospital/adminsignup.html',{'form':form})
def doctor_signup_view(request):
userForm=forms.DoctorUserForm()
doctorForm=forms.DoctorForm()
mydict={'userForm':userForm,'doctorForm':doctorForm}
if request.method=='POST':
userForm=forms.DoctorUserForm(request.POST)
doctorForm=forms.DoctorForm(request.POST,request.FILES)
if userForm.is_valid() and doctorForm.is_valid():
user=userForm.save()
user.set_password(user.password)
user.save()
doctor=doctorForm.save(commit=False)
doctor.user=user
doctor=doctor.save()
my_doctor_group = Group.objects.get_or_create(name='DOCTOR')
my_doctor_group[0].user_set.add(user)
return HttpResponseRedirect('doctorlogin')
return render(request,'hospital/doctorsignup.html',context=mydict)
def patient_signup_view(request):
userForm=forms.PatientUserForm()
patientForm=forms.PatientForm()
mydict={'userForm':userForm,'patientForm':patientForm}
if request.method=='POST':
userForm=forms.PatientUserForm(request.POST)
patientForm=forms.PatientForm(request.POST,request.FILES)
if userForm.is_valid() and patientForm.is_valid():
user=userForm.save()
user.set_password(user.password)
user.save()
patient=patientForm.save(commit=False)
patient.user=user
patient.assignedDoctorId=request.POST.get('assignedDoctorId')
patient=patient.save()
my_patient_group = Group.objects.get_or_create(name='PATIENT')
my_patient_group[0].user_set.add(user)
return HttpResponseRedirect('patientlogin')
return render(request,'hospital/patientsignup.html',context=mydict)
#-----------for checking user is doctor , patient or admin(by sumit)
def is_admin(user):
return user.groups.filter(name='ADMIN').exists()
def is_doctor(user):
return user.groups.filter(name='DOCTOR').exists()
def is_patient(user):
return user.groups.filter(name='PATIENT').exists()
#---------AFTER ENTERING CREDENTIALS WE CHECK WHETHER USERNAME AND PASSWORD IS OF ADMIN,DOCTOR OR PATIENT
def afterlogin_view(request):
if is_admin(request.user):
return redirect('admin-dashboard')
elif is_doctor(request.user):
accountapproval=models.Doctor.objects.all().filter(user_id=request.user.id,status=True)
if accountapproval:
return redirect('doctor-dashboard')
else:
return render(request,'hospital/doctor_wait_for_approval.html')
elif is_patient(request.user):
accountapproval=models.Patient.objects.all().filter(user_id=request.user.id,status=True)
if accountapproval:
return redirect('patient-dashboard')
else:
return render(request,'hospital/patient_wait_for_approval.html')
#---------------------------------------------------------------------------------
#------------------------ ADMIN RELATED VIEWS START ------------------------------
#---------------------------------------------------------------------------------
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def admin_dashboard_view(request):
#for both table in admin dashboard
doctors=models.Doctor.objects.all().order_by('-id')
patients=models.Patient.objects.all().order_by('-id')
#for three cards
doctorcount=models.Doctor.objects.all().filter(status=True).count()
pendingdoctorcount=models.Doctor.objects.all().filter(status=False).count()
patientcount=models.Patient.objects.all().filter(status=True).count()
pendingpatientcount=models.Patient.objects.all().filter(status=False).count()
appointmentcount=models.Appointment.objects.all().filter(status=True).count()
pendingappointmentcount=models.Appointment.objects.all().filter(status=False).count()
mydict={
'doctors':doctors,
'patients':patients,
'doctorcount':doctorcount,
'pendingdoctorcount':pendingdoctorcount,
'patientcount':patientcount,
'pendingpatientcount':pendingpatientcount,
'appointmentcount':appointmentcount,
'pendingappointmentcount':pendingappointmentcount,
}
return render(request,'hospital/admin_dashboard.html',context=mydict)
# this view for sidebar click on admin page
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def admin_doctor_view(request):
return render(request,'hospital/admin_doctor.html')
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def admin_view_doctor_view(request):
doctors=models.Doctor.objects.all().filter(status=True)
return render(request,'hospital/admin_view_doctor.html',{'doctors':doctors})
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def delete_doctor_from_hospital_view(request,pk):
doctor=models.Doctor.objects.get(id=pk)
user=models.User.objects.get(id=doctor.user_id)
user.delete()
doctor.delete()
return redirect('admin-view-doctor')
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def update_doctor_view(request,pk):
doctor=models.Doctor.objects.get(id=pk)
user=models.User.objects.get(id=doctor.user_id)
userForm=forms.DoctorUserForm(instance=user)
doctorForm=forms.DoctorForm(request.FILES,instance=doctor)
mydict={'userForm':userForm,'doctorForm':doctorForm}
if request.method=='POST':
userForm=forms.DoctorUserForm(request.POST,instance=user)
doctorForm=forms.DoctorForm(request.POST,request.FILES,instance=doctor)
if userForm.is_valid() and doctorForm.is_valid():
user=userForm.save()
user.set_password(user.password)
user.save()
doctor=doctorForm.save(commit=False)
doctor.status=True
doctor.save()
return redirect('admin-view-doctor')
return render(request,'hospital/admin_update_doctor.html',context=mydict)
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def admin_add_doctor_view(request):
userForm=forms.DoctorUserForm()
doctorForm=forms.DoctorForm()
mydict={'userForm':userForm,'doctorForm':doctorForm}
if request.method=='POST':
userForm=forms.DoctorUserForm(request.POST)
doctorForm=forms.DoctorForm(request.POST, request.FILES)
if userForm.is_valid() and doctorForm.is_valid():
user=userForm.save()
user.set_password(user.password)
user.save()
doctor=doctorForm.save(commit=False)
doctor.user=user
doctor.status=True
doctor.save()
my_doctor_group = Group.objects.get_or_create(name='DOCTOR')
my_doctor_group[0].user_set.add(user)
return HttpResponseRedirect('admin-view-doctor')
return render(request,'hospital/admin_add_doctor.html',context=mydict)
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def admin_approve_doctor_view(request):
#those whose approval are needed
doctors=models.Doctor.objects.all().filter(status=False)
return render(request,'hospital/admin_approve_doctor.html',{'doctors':doctors})
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def approve_doctor_view(request,pk):
doctor=models.Doctor.objects.get(id=pk)
doctor.status=True
doctor.save()
return redirect(reverse('admin-approve-doctor'))
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def reject_doctor_view(request,pk):
doctor=models.Doctor.objects.get(id=pk)
user=models.User.objects.get(id=doctor.user_id)
user.delete()
doctor.delete()
return redirect('admin-approve-doctor')
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def admin_view_doctor_specialisation_view(request):
doctors=models.Doctor.objects.all().filter(status=True)
return render(request,'hospital/admin_view_doctor_specialisation.html',{'doctors':doctors})
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def admin_patient_view(request):
return render(request,'hospital/admin_patient.html')
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def admin_view_patient_view(request):
patients=models.Patient.objects.all().filter(status=True)
return render(request,'hospital/admin_view_patient.html',{'patients':patients})
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def delete_patient_from_hospital_view(request,pk):
patient=models.Patient.objects.get(id=pk)
user=models.User.objects.get(id=patient.user_id)
user.delete()
patient.delete()
return redirect('admin-view-patient')
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def update_patient_view(request,pk):
patient=models.Patient.objects.get(id=pk)
user=models.User.objects.get(id=patient.user_id)
userForm=forms.PatientUserForm(instance=user)
patientForm=forms.PatientForm(request.FILES,instance=patient)
mydict={'userForm':userForm,'patientForm':patientForm}
if request.method=='POST':
userForm=forms.PatientUserForm(request.POST,instance=user)
patientForm=forms.PatientForm(request.POST,request.FILES,instance=patient)
if userForm.is_valid() and patientForm.is_valid():
user=userForm.save()
user.set_password(user.password)
user.save()
patient=patientForm.save(commit=False)
patient.status=True
patient.assignedDoctorId=request.POST.get('assignedDoctorId')
patient.save()
return redirect('admin-view-patient')
return render(request,'hospital/admin_update_patient.html',context=mydict)
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def admin_add_patient_view(request):
userForm=forms.PatientUserForm()
patientForm=forms.PatientForm()
mydict={'userForm':userForm,'patientForm':patientForm}
if request.method=='POST':
userForm=forms.PatientUserForm(request.POST)
patientForm=forms.PatientForm(request.POST,request.FILES)
if userForm.is_valid() and patientForm.is_valid():
user=userForm.save()
user.set_password(user.password)
user.save()
patient=patientForm.save(commit=False)
patient.user=user
patient.status=True
patient.assignedDoctorId=request.POST.get('assignedDoctorId')
patient.save()
my_patient_group = Group.objects.get_or_create(name='PATIENT')
my_patient_group[0].user_set.add(user)
return HttpResponseRedirect('admin-view-patient')
return render(request,'hospital/admin_add_patient.html',context=mydict)
#------------------FOR APPROVING PATIENT BY ADMIN----------------------
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def admin_approve_patient_view(request):
#those whose approval are needed
patients=models.Patient.objects.all().filter(status=False)
return render(request,'hospital/admin_approve_patient.html',{'patients':patients})
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def approve_patient_view(request,pk):
patient=models.Patient.objects.get(id=pk)
patient.status=True
patient.save()
return redirect(reverse('admin-approve-patient'))
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def reject_patient_view(request,pk):
patient=models.Patient.objects.get(id=pk)
user=models.User.objects.get(id=patient.user_id)
user.delete()
patient.delete()
return redirect('admin-approve-patient')
#--------------------- FOR DISCHARGING PATIENT BY ADMIN START-------------------------
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def admin_discharge_patient_view(request):
patients=models.Patient.objects.all().filter(status=True)
return render(request,'hospital/admin_discharge_patient.html',{'patients':patients})
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def discharge_patient_view(request,pk):
patient=models.Patient.objects.get(id=pk)
days=(date.today()-patient.admitDate) #2 days, 0:00:00
assignedDoctor=models.User.objects.all().filter(id=patient.assignedDoctorId)
d=days.days # only how many day that is 2
patientDict={
'patientId':pk,
'name':patient.get_name,
'mobile':patient.mobile,
'address':patient.address,
'symptoms':patient.symptoms,
'admitDate':patient.admitDate,
'todayDate':date.today(),
'day':d,
'assignedDoctorName':assignedDoctor[0].first_name,
}
if request.method == 'POST':
feeDict ={
'roomCharge':int(request.POST['roomCharge'])*int(d),
'doctorFee':request.POST['doctorFee'],
'medicineCost' : request.POST['medicineCost'],
'OtherCharge' : request.POST['OtherCharge'],
'total':(int(request.POST['roomCharge'])*int(d))+int(request.POST['doctorFee'])+int(request.POST['medicineCost'])+int(request.POST['OtherCharge'])
}
patientDict.update(feeDict)
#for updating to database patientDischargeDetails (pDD)
pDD=models.PatientDischargeDetails()
pDD.patientId=pk
pDD.patientName=patient.get_name
pDD.assignedDoctorName=assignedDoctor[0].first_name
pDD.address=patient.address
pDD.mobile=patient.mobile
pDD.symptoms=patient.symptoms
pDD.admitDate=patient.admitDate
pDD.releaseDate=date.today()
pDD.daySpent=int(d)
pDD.medicineCost=int(request.POST['medicineCost'])
pDD.roomCharge=int(request.POST['roomCharge'])*int(d)
pDD.doctorFee=int(request.POST['doctorFee'])
pDD.OtherCharge=int(request.POST['OtherCharge'])
pDD.total=(int(request.POST['roomCharge'])*int(d))+int(request.POST['doctorFee'])+int(request.POST['medicineCost'])+int(request.POST['OtherCharge'])
pDD.save()
return render(request,'hospital/patient_final_bill.html',context=patientDict)
return render(request,'hospital/patient_generate_bill.html',context=patientDict)
#--------------for discharge patient bill (pdf) download and printing
import io
from xhtml2pdf import pisa
from django.template.loader import get_template
from django.template import Context
from django.http import HttpResponse
def render_to_pdf(template_src, context_dict):
template = get_template(template_src)
html = template.render(context_dict)
result = io.BytesIO()
pdf = pisa.pisaDocument(io.BytesIO(html.encode("ISO-8859-1")), result)
if not pdf.err:
return HttpResponse(result.getvalue(), content_type='application/pdf')
return
def download_pdf_view(request,pk):
dischargeDetails=models.PatientDischargeDetails.objects.all().filter(patientId=pk).order_by('-id')[:1]
dict={
'patientName':dischargeDetails[0].patientName,
'assignedDoctorName':dischargeDetails[0].assignedDoctorName,
'address':dischargeDetails[0].address,
'mobile':dischargeDetails[0].mobile,
'symptoms':dischargeDetails[0].symptoms,
'admitDate':dischargeDetails[0].admitDate,
'releaseDate':dischargeDetails[0].releaseDate,
'daySpent':dischargeDetails[0].daySpent,
'medicineCost':dischargeDetails[0].medicineCost,
'roomCharge':dischargeDetails[0].roomCharge,
'doctorFee':dischargeDetails[0].doctorFee,
'OtherCharge':dischargeDetails[0].OtherCharge,
'total':dischargeDetails[0].total,
}
return render_to_pdf('hospital/download_bill.html',dict)
#-----------------APPOINTMENT START--------------------------------------------------------------------
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def admin_appointment_view(request):
return render(request,'hospital/admin_appointment.html')
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def admin_view_appointment_view(request):
appointments=models.Appointment.objects.all().filter(status=True)
return render(request,'hospital/admin_view_appointment.html',{'appointments':appointments})
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def admin_add_appointment_view(request):
appointmentForm=forms.AppointmentForm()
mydict={'appointmentForm':appointmentForm,}
if request.method=='POST':
appointmentForm=forms.AppointmentForm(request.POST)
if appointmentForm.is_valid():
appointment=appointmentForm.save(commit=False)
appointment.doctorId=request.POST.get('doctorId')
appointment.patientId=request.POST.get('patientId')
appointment.doctorName=models.User.objects.get(id=request.POST.get('doctorId')).first_name
appointment.patientName=models.User.objects.get(id=request.POST.get('patientId')).first_name
appointment.status=True
appointment.save()
return HttpResponseRedirect('admin-view-appointment')
return render(request,'hospital/admin_add_appointment.html',context=mydict)
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def admin_approve_appointment_view(request):
#those whose approval are needed
appointments=models.Appointment.objects.all().filter(status=False)
return render(request,'hospital/admin_approve_appointment.html',{'appointments':appointments})
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def approve_appointment_view(request,pk):
appointment=models.Appointment.objects.get(id=pk)
appointment.status=True
appointment.save()
return redirect(reverse('admin-approve-appointment'))
@login_required(login_url='adminlogin')
@user_passes_test(is_admin)
def reject_appointment_view(request,pk):
appointment=models.Appointment.objects.get(id=pk)
appointment.delete()
return redirect('admin-approve-appointment')
#---------------------------------------------------------------------------------
#------------------------ ADMIN RELATED VIEWS END ------------------------------
#---------------------------------------------------------------------------------
#---------------------------------------------------------------------------------
#------------------------ DOCTOR RELATED VIEWS START ------------------------------
#---------------------------------------------------------------------------------
@login_required(login_url='doctorlogin')
@user_passes_test(is_doctor)
def doctor_dashboard_view(request):
#for three cards
patientcount=models.Patient.objects.all().filter(status=True,assignedDoctorId=request.user.id).count()
appointmentcount=models.Appointment.objects.all().filter(status=True,doctorId=request.user.id).count()
patientdischarged=models.PatientDischargeDetails.objects.all().distinct().filter(assignedDoctorName=request.user.first_name).count()
#for table in doctor dashboard
appointments=models.Appointment.objects.all().filter(status=True,doctorId=request.user.id).order_by('-id')
patientid=[]
for a in appointments:
patientid.append(a.patientId)
patients=models.Patient.objects.all().filter(status=True,user_id__in=patientid).order_by('-id')
appointments=zip(appointments,patients)
mydict={
'patientcount':patientcount,
'appointmentcount':appointmentcount,
'patientdischarged':patientdischarged,
'appointments':appointments,
'doctor':models.Doctor.objects.get(user_id=request.user.id), #for profile picture of doctor in sidebar
}
return render(request,'hospital/doctor_dashboard.html',context=mydict)
@login_required(login_url='doctorlogin')
@user_passes_test(is_doctor)
def doctor_patient_view(request):
mydict={
'doctor':models.Doctor.objects.get(user_id=request.user.id), #for profile picture of doctor in sidebar
}
return render(request,'hospital/doctor_patient.html',context=mydict)
@login_required(login_url='doctorlogin')
@user_passes_test(is_doctor)
def doctor_view_patient_view(request):
patients=models.Patient.objects.all().filter(status=True,assignedDoctorId=request.user.id)
doctor=models.Doctor.objects.get(user_id=request.user.id) #for profile picture of doctor in sidebar
return render(request,'hospital/doctor_view_patient.html',{'patients':patients,'doctor':doctor})
@login_required(login_url='doctorlogin')
@user_passes_test(is_doctor)
def search_view(request):
doctor=models.Doctor.objects.get(user_id=request.user.id) #for profile picture of doctor in sidebar
# whatever user write in search box we get in query
query = request.GET['query']
patients=models.Patient.objects.all().filter(status=True,assignedDoctorId=request.user.id).filter(Q(symptoms__icontains=query)|Q(user__first_name__icontains=query))
return render(request,'hospital/doctor_view_patient.html',{'patients':patients,'doctor':doctor})
@login_required(login_url='doctorlogin')
@user_passes_test(is_doctor)
def doctor_view_discharge_patient_view(request):
dischargedpatients=models.PatientDischargeDetails.objects.all().distinct().filter(assignedDoctorName=request.user.first_name)
doctor=models.Doctor.objects.get(user_id=request.user.id) #for profile picture of doctor in sidebar
return render(request,'hospital/doctor_view_discharge_patient.html',{'dischargedpatients':dischargedpatients,'doctor':doctor})
@login_required(login_url='doctorlogin')
@user_passes_test(is_doctor)
def doctor_appointment_view(request):
doctor=models.Doctor.objects.get(user_id=request.user.id) #for profile picture of doctor in sidebar
return render(request,'hospital/doctor_appointment.html',{'doctor':doctor})
@login_required(login_url='doctorlogin')
@user_passes_test(is_doctor)
def doctor_view_appointment_view(request):
doctor=models.Doctor.objects.get(user_id=request.user.id) #for profile picture of doctor in sidebar
appointments=models.Appointment.objects.all().filter(status=True,doctorId=request.user.id)
patientid=[]
for a in appointments:
patientid.append(a.patientId)
patients=models.Patient.objects.all().filter(status=True,user_id__in=patientid)
appointments=zip(appointments,patients)
return render(request,'hospital/doctor_view_appointment.html',{'appointments':appointments,'doctor':doctor})
@login_required(login_url='doctorlogin')
@user_passes_test(is_doctor)
def doctor_delete_appointment_view(request):
doctor=models.Doctor.objects.get(user_id=request.user.id) #for profile picture of doctor in sidebar
appointments=models.Appointment.objects.all().filter(status=True,doctorId=request.user.id)
patientid=[]
for a in appointments:
patientid.append(a.patientId)
patients=models.Patient.objects.all().filter(status=True,user_id__in=patientid)
appointments=zip(appointments,patients)
return render(request,'hospital/doctor_delete_appointment.html',{'appointments':appointments,'doctor':doctor})
@login_required(login_url='doctorlogin')
@user_passes_test(is_doctor)
def delete_appointment_view(request,pk):
appointment=models.Appointment.objects.get(id=pk)
appointment.delete()
doctor=models.Doctor.objects.get(user_id=request.user.id) #for profile picture of doctor in sidebar
appointments=models.Appointment.objects.all().filter(status=True,doctorId=request.user.id)
patientid=[]
for a in appointments:
patientid.append(a.patientId)
patients=models.Patient.objects.all().filter(status=True,user_id__in=patientid)
appointments=zip(appointments,patients)
return render(request,'hospital/doctor_delete_appointment.html',{'appointments':appointments,'doctor':doctor})
#---------------------------------------------------------------------------------
#------------------------ DOCTOR RELATED VIEWS END ------------------------------
#---------------------------------------------------------------------------------
#---------------------------------------------------------------------------------
#------------------------ PATIENT RELATED VIEWS START ------------------------------
#---------------------------------------------------------------------------------
@login_required(login_url='patientlogin')
@user_passes_test(is_patient)
def patient_dashboard_view(request):
patient=models.Patient.objects.get(user_id=request.user.id)
doctor=models.Doctor.objects.get(user_id=patient.assignedDoctorId)
mydict={
'patient':patient,
'doctorName':doctor.get_name,
'doctorMobile':doctor.mobile,
'doctorAddress':doctor.address,
'symptoms':patient.symptoms,
'doctorDepartment':doctor.department,
'admitDate':patient.admitDate,
}
return render(request,'hospital/patient_dashboard.html',context=mydict)
@login_required(login_url='patientlogin')
@user_passes_test(is_patient)
def patient_appointment_view(request):
patient=models.Patient.objects.get(user_id=request.user.id) #for profile picture of patient in sidebar
return render(request,'hospital/patient_appointment.html',{'patient':patient})
@login_required(login_url='patientlogin')
@user_passes_test(is_patient)
def patient_book_appointment_view(request):
appointmentForm=forms.PatientAppointmentForm()
patient=models.Patient.objects.get(user_id=request.user.id) #for profile picture of patient in sidebar
message=None
mydict={'appointmentForm':appointmentForm,'patient':patient,'message':message}
if request.method=='POST':
appointmentForm=forms.PatientAppointmentForm(request.POST)
if appointmentForm.is_valid():
print(request.POST.get('doctorId'))
desc=request.POST.get('description')
doctor=models.Doctor.objects.get(user_id=request.POST.get('doctorId'))
appointment=appointmentForm.save(commit=False)
appointment.doctorId=request.POST.get('doctorId')
appointment.patientId=request.user.id #----user can choose any patient but only their info will be stored
appointment.doctorName=models.User.objects.get(id=request.POST.get('doctorId')).first_name
appointment.patientName=request.user.first_name #----user can choose any patient but only their info will be stored
appointment.status=False
appointment.save()
return HttpResponseRedirect('patient-view-appointment')
return render(request,'hospital/patient_book_appointment.html',context=mydict)
def patient_view_doctor_view(request):
doctors=models.Doctor.objects.all().filter(status=True)
patient=models.Patient.objects.get(user_id=request.user.id) #for profile picture of patient in sidebar
return render(request,'hospital/patient_view_doctor.html',{'patient':patient,'doctors':doctors})
def search_doctor_view(request):
patient=models.Patient.objects.get(user_id=request.user.id) #for profile picture of patient in sidebar
# whatever user write in search box we get in query
query = request.GET['query']
doctors=models.Doctor.objects.all().filter(status=True).filter(Q(department__icontains=query)| Q(user__first_name__icontains=query))
return render(request,'hospital/patient_view_doctor.html',{'patient':patient,'doctors':doctors})
@login_required(login_url='patientlogin')
@user_passes_test(is_patient)
def patient_view_appointment_view(request):
patient=models.Patient.objects.get(user_id=request.user.id) #for profile picture of patient in sidebar
appointments=models.Appointment.objects.all().filter(patientId=request.user.id)
return render(request,'hospital/patient_view_appointment.html',{'appointments':appointments,'patient':patient})
@login_required(login_url='patientlogin')
@user_passes_test(is_patient)
def patient_discharge_view(request):
patient=models.Patient.objects.get(user_id=request.user.id) #for profile picture of patient in sidebar
dischargeDetails=models.PatientDischargeDetails.objects.all().filter(patientId=patient.id).order_by('-id')[:1]
patientDict=None
if dischargeDetails:
patientDict ={
'is_discharged':True,
'patient':patient,
'patientId':patient.id,
'patientName':patient.get_name,
'assignedDoctorName':dischargeDetails[0].assignedDoctorName,
'address':patient.address,
'mobile':patient.mobile,
'symptoms':patient.symptoms,
'admitDate':patient.admitDate,
'releaseDate':dischargeDetails[0].releaseDate,
'daySpent':dischargeDetails[0].daySpent,
'medicineCost':dischargeDetails[0].medicineCost,
'roomCharge':dischargeDetails[0].roomCharge,
'doctorFee':dischargeDetails[0].doctorFee,
'OtherCharge':dischargeDetails[0].OtherCharge,
'total':dischargeDetails[0].total,
}
print(patientDict)
else:
patientDict={
'is_discharged':False,
'patient':patient,
'patientId':request.user.id,
}
return render(request,'hospital/patient_discharge.html',context=patientDict)
#------------------------ PATIENT RELATED VIEWS END ------------------------------
#---------------------------------------------------------------------------------
#---------------------------------------------------------------------------------
#------------------------ ABOUT US AND CONTACT US VIEWS START ------------------------------
#---------------------------------------------------------------------------------
def aboutus_view(request):
return render(request,'hospital/aboutus.html')
def contactus_view(request):
sub = forms.ContactusForm()
if request.method == 'POST':
sub = forms.ContactusForm(request.POST)
if sub.is_valid():
email = sub.cleaned_data['Email']
name=sub.cleaned_data['Name']
message = sub.cleaned_data['Message']
send_mail(str(name)+' || '+str(email),message,settings.EMAIL_HOST_USER, settings.EMAIL_RECEIVING_USER, fail_silently = False)
return render(request, 'hospital/contactussuccess.html')
return render(request, 'hospital/contactus.html', {'form':sub})
#---------------------------------------------------------------------------------
#------------------------ ADMIN RELATED VIEWS END ------------------------------
#---------------------------------------------------------------------------------
#Developed By : sumit kumar
#facebook : fb.com/sumit.luv
#Youtube :youtube.com/lazycoders