-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
387 lines (268 loc) · 10.6 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
from django.http.response import HttpResponse
from django.shortcuts import render , redirect
from django.forms import inlineformset_factory
from django.views.generic import ListView , DetailView , CreateView , DeleteView
from django.views.generic.edit import UpdateView
from .models import *
# from django.contrib.auth.forms import UserCreationForm
from .forms import CreateUserForm
from django.contrib import messages
from django.contrib.auth import authenticate,login,logout
from django.contrib.auth.decorators import login_required
# from .models import Pill
# from .forms import PillForm
from django.urls import reverse_lazy
from django.contrib.auth.mixins import LoginRequiredMixin
from datetime import time
import joblib
def get_part_of_day(h):
return (
"morning"
if 5 <= h <= 11
else "afternoon"
if 12 <= h <= 17
else "evening"
if 18 <= h <= 22
else "night"
)
# To use current hour:
# part = get_part_of_day(datetime.now().hour)
# print(f"Have a good {part}!")
# for hour in range(0, 24):
# part = get_part_of_day(hour)
# print(f"hour {hour} is {part}")
def landing(request):
return render(request,'users/landing.html')
def about(request):
return render(request,'users/about.html')
def contact(request):
return render(request,'users/contact.html')
def registerpage(request):
if request.user.is_authenticated:
return redirect('dashboard')
else:
form = CreateUserForm()
if request.method=='POST':
form = CreateUserForm(request.POST)
if form.is_valid():
form.save()
user=form.cleaned_data.get('username')
messages.success(request,'Account created successfully for' + user)
return redirect('login')
context={'form':form}
return render(request,'users/register.html',context)
def loginpage(request):
if request.user.is_authenticated:
return redirect('dashboard')
else:
if request.method =='POST':
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(request,username=username,password=password)
if user is not None:
login(request,user)
return redirect('dashboard')
else:
messages.info(request,'Username or Password is incorrect')
context={}
return render(request,'users/login.html',context)
def logoutUser(request):
logout(request)
return redirect('landing')
# ----------------------------------------------------------------
@login_required(login_url = 'login')
def dashboard(request):
log_user = request.user
med_list = Medicine.objects.filter(user=log_user)
return render(request,'users/dashboard.html',{'med_list':med_list.order_by('drug_time')})
#-----------------------------------------------------------------
@login_required(login_url = 'login')
def profile(request):
return render(request,'users/profile.html')
@login_required(login_url = 'login')
def foodrecom(request):
# form = show_entry_fields()
return render(request,'users/foodrecom.html',{'form':form})
@login_required(login_url = 'login')
def result(request):
classifier = joblib.load("C:/Users/Joyeeta/Desktop/PillPlan-Medicine-Adherence/finalized_usertype.sav")
lis = []
lis.append(request.GET['q1'])
lis.append(request.GET['q2'])
lis.append(request.GET['q3'])
lis.append(request.GET['q4'])
lis.append(request.GET['q5'])
lis.append(request.GET['q6'])
lis.append(request.GET['q7'])
lis.append(request.GET['q8'])
lis.append(request.GET['q9'])
lis.append(request.GET['q10'])
ans = classifier.predict([lis])
if(ans[0]=='nun'):
return redirect('usertype_un')
elif(ans[0]=='adh'):
return redirect('gamification')
else:
return redirect('usertype_in')
@login_required(login_url = 'login')
def gettype(request):
return render(request,'users/gettype.html')
@login_required(login_url = 'login')
def financeinfo(request):
return render(request,'users/financeinfo.html')
#----------------------------------------------------------------------------------------
@login_required(login_url = 'login')
def bmi(request):
return render(request,'users/bmi.html')
import numpy as np
@login_required(login_url = 'login')
def bmiresult(request):
clsf = joblib.load("C:/Users/Joyeeta/Desktop/optum/PillPlan-Medicine-Adherence/optum/bmi.sav")
# lis = []
# lis.append(request.GET['height'])
# lis.append(request.GET['weight'])
# lis.append(request.GET['gender'])
# ans = clsf.predict([lis])
# return render(request,'users/bmiresult.html',{'ans':ans})
if request.method == 'POST':
a1 = float(request.POST['height'])
a2 = float(request.POST['weight'])
a3 = float(request.POST['gender'])
list1=[[a1,a2,a3]]
prediction = clsf.predict(list1)
output = prediction[0]
t1='Result: Extremely Weak'
t2='Result: Weak'
t3='Result: Normal'
t4='Result: Overweight'
t5='Result: Obesity'
t6='Result: Extreme Obesity'
t7='Can\'t Predict'
if(output==0):
return render(request,'users/bmi_result.html', {'prediction_text':t1})
elif(output==1):
return render(request,'users/bmi_result.html', {'prediction_text':t2})
elif(output==2):
return render(request,'users/bmi_result.html', {'prediction_text':t3})
elif(output==3):
return render(request,'users/bmi_result.html', {'prediction_text':t4})
elif(output==4):
return render(request,'users/bmi_result.html', {'prediction_text':t5})
elif(output==5):
return render(request,'users/bmi_result.html', {'prediction_text':t6})
else:
return render(request,'users/bmi_result.html', {'prediction_text':t7})
@login_required(login_url = 'login')
def medicineList(request):
return render(request,'users/medicinelist.html')
class TaskList(LoginRequiredMixin,ListView):
model = Medicine
context_object_name = 'medicines'
template_name = "users/Medicines/medicinelist.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['medicines'] = context['medicines'].filter(user=self.request.user)
context['count'] = context['medicines'].filter(complete=False).count()
context['drug_time'] = context['medicines'].filter(complete=False)
return context
# @login_required(login_url = 'login')
# def medicines(request):
# dd1 = time(12,0)
# log_user = request.user
# med_list = Medicine.objects.filter(user=log_user)
# drug_time = Medicine.objects.values('drug_time').filter(user=log_user)
# # if(drug_time < dd1):
# # time1 = "Morning"
# # else:
# # time1 = "eveing"
# return render(request,'users/Medicines/medicinelist.html',{'med_list':med_list.order_by('drug_time'), 'time':drug_time})
class TaskDetail(LoginRequiredMixin,DetailView):
model = Medicine
context_object_name = 'medicine'
template_name = "users/Medicines/medicinedetail.html"
class TaskCreate(LoginRequiredMixin,CreateView):
model = Medicine
fields = ['title','description','drug_type','drug_qty','drug_frequency','drug_time']
template_name = "users/Medicines/medicineform.html"
success_url = reverse_lazy('medicines')
def form_valid(self,form):
form.instance.user = self.request.user
return super(TaskCreate,self).form_valid(form)
class TaskUpdate(LoginRequiredMixin,UpdateView):
model=Medicine
fields = ['title','description','complete','drug_type','drug_qty','drug_frequency','upload','man_date','exp_date','drug_time','drug_comments']
template_name = "users/Medicines/medicineform.html"
success_url = reverse_lazy('medicines')
# 'start_date','end_date'
class TaskDelete(LoginRequiredMixin,DeleteView):
model=Medicine
context_object_name = 'medicine'
template_name = "users/Medicines/medicine_confirm_delete.html"
success_url = reverse_lazy('medicines')
# ------------------------------------------------------------------------------------------------------------
# @login_required(login_url = 'login')
@login_required(login_url = 'login')
def gamification(request):
return render(request,'games/gamehome.html')
@login_required(login_url = 'login')
def infogame(request):
return render(request,'games/infogame.html')
@login_required(login_url = 'login')
def infogame1(request):
return render(request,'games/infogame1.html')
@login_required(login_url = 'login')
def infogame2(request):
return render(request,'games/infogame2.html')
@login_required(login_url = 'login')
def infogame3(request):
return render(request,'games/infogame3.html')
@login_required(login_url = 'login')
def videos(request):
return render(request,'games/videos.html')
@login_required(login_url = 'login')
def gameboard(request):
user_list = MyUser.objects.all().order_by('-user_points')
return render(request,'users/gameboard.html',{'user_list':user_list})
@login_required(login_url = 'login')
def usertype_un(request):
return render(request,'users/usertype_un.html')
@login_required(login_url = 'login')
def usertype_in(request):
return render(request,'users/usertype_in.html')
@login_required(login_url = 'login')
def data(request):
return render(request,'users/data.html')
@login_required(login_url = 'login')
def drugdrug(request):
return render(request,'users/drugdrug.html')
import pandas as pd
@login_required(login_url = 'login')
def drugdrugresult(request):
df = pd.read_csv('C:/Users/Joyeeta/Desktop/optum/newclone/PillPlan-Medicine-Adherence/optum/users/drug-drug.csv')
df.rename(columns = {'object ':'object'}, inplace = True)
flag=0
if request.method == 'POST':
drug1 = (request.POST['drug1'])
drug2 = (request.POST['drug2'])
for index, row in df.iterrows():
if(row['object']==drug1 and row['precipitant']==drug2):
flag=1
break
else:
flag=0
msg = []
if(flag==1):
msg.append(row['Effect'])
msg.append(row['Related Drugs'])
msg.append(row['Options'])
else:
msg.append("No Interaction")
msg.append("None")
msg.append("None")
return render(request,'users/drugdrugresult.html',{'effect':msg[0],'related':msg[1],'options':msg[2]})
@login_required(login_url = 'login')
def carepartner(request):
return render(request,'users/carepartner.html')
@login_required(login_url = 'login')
def foodallergy(request):
return render(request,'users/food-allergy.html')