def login(request): email = request.POST['email'] password = request.POST['password'] #Validation checks if (len(email) > 254): messages.info( request, "Invalid Email! Email can't have more than 254 characters.") elif (len(email) < 8): messages.info( request, "Invalid Email! Email must contain atleast 8 characters") elif (len(password) < 8): messages.info( request, "Invalid Password! Password must contain atleast 8 characters.") elif (len(password) > 50): messages.info( request, "Invalid Password! Password can't have more than 50 characters.") else: login_feedback = authenticate.login(request, email, password) if (login_feedback is not None): request.session['email'] = email request.session['userid'] = login_feedback request.session['isRegistered'] = user_data.isRegisteredUser( login_feedback) messages.info(request, 'Login Successful!') return redirect("/") else: messages.info(request, "Wrong Email or password!") return redirect("/accounts/signin")
def profile(request, uid): uid = int(uid) if (user_data.isUser(uid)): user_type = user_data.getUserType(uid) if (user_data.isRegisteredUser(uid)): if (user_type == "Patient"): return redirect("/Profile/" + str(uid)) elif (user_type == "Doctor"): doctor_data = user_data.getDoctorData(uid) if doctor_data['Fee'] is None: messages.info( request, "Sorry, The Doctor's Department Has Been Removed By The Hospital!" ) return redirect("/") try: mydate = request.session['date'] mydate = datetime.datetime.strptime(mydate, '%Y-%m-%d') except: mydate = datetime.datetime.now() + datetime.timedelta( days=1) request.session['date'] = str(mydate.date()) doctor_data['AvailableSlots'] = user_data.getFreeSlots( uid, str(mydate).split()[0]) doctor_data['SelectedDate'] = mydate doctor_data['Today'] = datetime.datetime.now() try: mode = request.session['mode'] except: mode = "Online" request.session['mode'] = "Online" doctor_data['SelectedMode'] = mode if (request.user.is_authenticated): #User is logged in fid = request.session['userid'] doctor_data['Following'] = user_data.isFollowing(uid, fid) doctor_data['MyRating'] = user_data.userRating(uid, fid) if (uid == fid): doctor_data["Myself"] = True else: doctor_data["Myself"] = False else: #User not logged in doctor_data['Following'] = False doctor_data['MyRating'] = 0 return render(request, 'user_app/DoctorProfile.html', doctor_data) else: return redirect("/Profile/" + str(uid)) else: messages.info(request, "This User Hasn't Completed Registeration yet!") else: messages.info(request, "Sorry, No Such User Exists!") return redirect("/")
def register_tlab(request): phone = request.POST['phone'] country = request.POST['country'] state = request.POST['state'] city = request.POST['city'] area = request.POST['area'] zip = int(request.POST['zip']) pic1 = None specialization = request.POST.getlist('specialization') certificate = None if 'proof' in request.FILES: certificate = request.FILES['proof'] else: messages.info( request, 'Please Upload A Valid Licsense Or Certification Of Hospital.') return redirect("/accounts/signup/hospital") if 'pic1' in request.FILES: pic1 = request.FILES['pic1'] test_pricing = dict() for sp in specialization: test_pricing[sp] = request.POST[sp] # Validation checks if (len(phone) == 0): messages.info(request, "Invalid Phone Number! Phone Number can't be empty.") elif (len(phone) > 10): messages.info( request, "Invalid Phone Number! Phone Number can't have more than 10 characters." ) elif (authenticate.hasRegisteredPhone(phone, "Hospital")): messages.info(request, 'This Phone is already registered!') else: phone = int(phone) if (request.user.is_authenticated): uid = request.session['userid'] if (authenticate.registerTLab(uid, phone, country, state, city, zip, area, test_pricing, pic1, certificate)): request.session['isRegistered'] = user_data.isRegisteredUser( request.session['userid']) messages.info( request, 'Registeration Successful! Your account will be verified soon after review by our team.' ) return redirect("/") else: messages.info(request, "Registeration Failed!") else: messages.info(request, "Please Login Before Submitting Details!") return redirect("/accounts/signup/hospital")
def register_patient(request): phone = request.POST['phone'] country = request.POST['country'] state = request.POST['state'] city = request.POST['city'] area = request.POST['area'] zip = int(request.POST['zip']) gender = request.POST['gender'] age = int(request.POST['age']) disability = request.POST['disability'] profilepic = None if 'profilepic' in request.FILES: profilepic = request.FILES['profilepic'] #Validation checks if (len(phone) == 0): messages.info(request, "Invalid Phone Number! Phone Number can't be empty.") elif (len(phone) > 10): messages.info( request, "Invalid Phone Number! Phone Number can't have more than 10 characters." ) elif (authenticate.hasRegisteredPhone(phone, "Patient")): messages.info(request, 'This Phone is already registered!') else: phone = int(phone) if (request.user.is_authenticated): uid = request.session['userid'] if (authenticate.registerPatient(uid, phone, country, state, city, area, zip, gender, age, disability, profilepic)): request.session['isRegistered'] = user_data.isRegisteredUser( request.session['userid']) messages.info( request, 'Registeration Successful! Your account is fully activated.' ) return redirect("/") else: messages.info(request, "Registeration Failed!") else: messages.info(request, "Please Login Before Submitting Details!") return redirect("/accounts/signup/patient")
def searchResults(searchtext): resultobjects = UserDetails.objects.exclude(user_type = "Patient").filter(name__icontains=searchtext) results = [] for obj in resultobjects: if(user_data.isRegisteredUser(obj.userid+1)): sr = SearchResult() sr.name = obj.name sr.user_type = obj.user_type sr.email = obj.email sr.uid = obj.userid specificobj = None # try: if sr.user_type == "Doctor": specificobj = Doctor.objects.get(doctorid = sr.uid) if specificobj.is_independent: sr.address = specificobj.clinic_name + ", " + specificobj.area + ", " + specificobj.city + ", " + specificobj.state + ", " + specificobj.country sr.fee = specificobj.clinic_fee else: hobj = specificobj.hospitalid huserobj = hobj.hospitalid hospitalid = huserobj.userid sr.address = huserobj.name + ", " + hobj.area + ", " + hobj.city + ", " + hobj.state + ", " + hobj.country hospitalspeciality=HospitalSpeciality.objects.get(hospitalid=hospitalid, speciality = specificobj.specialization) sr.fee = hospitalspeciality.price sr.fee = "Rs. "+str(sr.fee)+" Only." elif sr.user_type == "Hospital": specificobj = Hospital.objects.get(hospitalid = sr.uid) sr.fee = "Depends On Specialization." sr.address = sr.name + ", " + specificobj.area + ", " + specificobj.city + ", " + specificobj.state + ", " + specificobj.country else: specificobj = TestingLab.objects.get(tlabid = sr.uid) sr.fee = "Depends On Medical Test." sr.address = sr.name + ", " + specificobj.area + ", " + specificobj.city + ", " + specificobj.state + ", " + specificobj.country # except: # print(sys.exc_info()) # break sr.phone = specificobj.phone sr.verified = specificobj.verified if specificobj.start_time is None: sr.timings = "Not Specified" else: st = specificobj.start_time if st == "00:00": st = "12:00 AM" elif st < "12:00": st+= " AM" else: hr=int(st[0:2])-12 if hr<10: hr = "0"+str(hr) else: hr = str(hr) st = str(hr) + st[2:] st += " PM" et = specificobj.end_time if et == "00:00": et = "12:00 AM" elif et < "12:00": et+= " AM" else: hr=int(et[0:2])-12 if hr<10: hr = "0"+str(hr) else: hr = str(hr) et = hr + et[2:] et += " PM" sr.timings = st + " To " + et results.append(sr) return results
def edit_profile(request): if (request.user.is_authenticated): #User is logged in uid = request.session['userid'] user_type = user_data.getUserType(uid) if (user_data.isRegisteredUser(uid)): if (user_type == "Doctor"): doctor_data = user_data.getDoctorData(uid) doctor_data[ 'AllSpecialities'] = medical_speciality.get_specialities() doctor_data['Countries'] = location.getCountries() doctor_data['States'] = location.get_states( doctor_data['Country']) doctor_data['Cities'] = location.list_of_cities1( doctor_data['State']) doctor_data['AllGenders'] = [ 'Male', 'Female', 'Trans', 'Unknown' ] if (doctor_data["independent"]): doctor_data['HospitalId'] = "" else: doctor_data['HospitalId'] = user_data.getHospitalId(uid) return render(request, 'user_app/EditDoctorProfile.html', doctor_data) elif (user_type == "Hospital"): hp_data = user_data.getHospitalData(uid) hp_data[ 'AllSpecialities'] = medical_speciality.get_specialities() hp_data['Countries'] = location.getCountries() hp_data['States'] = location.get_states(hp_data['Country']) hp_data['Cities'] = location.list_of_cities1(hp_data['State']) return render(request, 'user_app/EditHospitalProfile.html', hp_data) elif (user_type == "Testing Lab"): tl_data = user_data.getTestingLabData(uid) tl_data['tests'] = medical_tests.getTests() tl_data['Countries'] = location.getCountries() tl_data['States'] = location.get_states(tl_data['Country']) tl_data['Cities'] = location.list_of_cities1(tl_data['State']) return render(request, 'user_app/EditTLabProfile.html', tl_data) elif (user_type == "Patient"): pt_data = user_data.getPatientData(uid) pt_data['AllGenders'] = ['Male', 'Female', 'Trans', 'Unknown'] pt_data['AllBG'] = [ 'A+ve', 'A-ve', 'B+ve', 'B-ve', 'AB+ve', 'AB-ve', 'O+ve', 'O-ve', 'HH+ve', 'HH-ve', 'Unknown' ] pt_data['Countries'] = location.getCountries() pt_data['States'] = location.get_states(pt_data['Country']) pt_data['Cities'] = location.list_of_cities1(pt_data['State']) return render(request, 'user_app/EditPatientProfile.html', pt_data) else: messages.info(request, "Please Complete Your Account Registeration.") return redirect("/accounts/signup/redirect") else: #User not logged in messages.info(request, "You are not Logged In!") return redirect("/accounts/signin")
def register_doctor(request): start_time = request.POST['start_time'] end_time = request.POST['end_time'] phone = request.POST['phone'] is_independent = (request.POST['is_independent'] == "True") gender = request.POST['gender'] experience = int(request.POST['experience']) specialization = request.POST['specialization'] proof = None if 'proof' in request.FILES: proof = request.FILES['proof'] else: messages.info(request, 'Please Upload Proof of Claimed Qualification.') return redirect("/accounts/signup/doctor") hospitalid = None cname = "" cphoto = None fee = None country = "" state = "" city = "" area = "" zip = None if (is_independent): cname = request.POST['cname'] if 'cphoto' in request.FILES: cphoto = request.FILES['cphoto'] fee = int(request.POST['fee']) country = request.POST['country'] state = request.POST['state'] city = request.POST['city'] area = request.POST['area'] zip = int(request.POST['zip']) else: hospitalid = int(request.POST['hospitalid']) #Validation checks if (len(phone) == 0): messages.info(request, "Invalid Phone Number! Phone Number can't be empty.") elif (len(phone) > 10): messages.info( request, "Invalid Phone Number! Phone Number can't have more than 10 characters." ) elif (authenticate.hasRegisteredPhone(phone, "Doctor")): messages.info(request, 'This Phone is already registered!') else: phone = int(phone) if (request.user.is_authenticated): uid = request.session['userid'] if (authenticate.registerDoctor(uid, start_time, end_time, phone, is_independent, gender, experience, specialization, proof, hospitalid, cname, cphoto, fee, country, state, city, area, zip)): messages.info( request, 'Registeration Successful! Your account will be verified soon after review by our team.' ) request.session['isRegistered'] = user_data.isRegisteredUser( request.session['userid']) return redirect("/") else: messages.info(request, "Registeration Failed!") else: messages.info(request, "Please Login Before Submitting Details.") return redirect("/accounts/signup/doctor")