Beispiel #1
0
def symp_list(request):
    if is_authenticated != 0:
        table = Table('symp')
        res = table.scan(FilterExpression={}).values()
        if request.method == "GET":
            for i in res['Items']:
                i['_id'] = str(i['_id'])
            return Response(res)

        elif request.method == 'POST':
            symp_data = request.data
            if symp_data['method'] == 'get_symptoms':
                res = table.scan(FilterExpression={
                    'symp_id': symp_data['symp_id']
                }).values()
                for i in res['Items']:
                    i['_id'] = str(i['_id'])
                return Response(res)
            elif symp_data['method'] == 'add_symptoms':
                for id in res['Items']:
                    # print(id, type(id))
                    sid = id['symp_id']
                sid = int(sid) + 1
                table.insertValues(values=[{
                    'symp_id': str(sid),
                    'symp': symp_data['symp']
                }])
                return HttpResponse("Added Symptoms")
            elif symp_data['method'] == 'delete_symptoms':
                table.delete(
                    FilterExpression={'symp_id': symp_data['symp_id']})
                return HttpResponse("Deleted that slot id")
Beispiel #2
0
        def wrapper_function(*args, **kwargs):
            if 'session_key' in args[0].session:
                session_key = args[0].session['session_key']
                table = Table("SessionStore")
                response = table.scan(FilterExpression={
                    'session_key': session_key,
                }, ).values()

                if response['Count'] == 0:
                    return HttpResponseRedirect('/accounts/login/')

                isDoctor0 = response['Items'][0]['isDoctor']
                isVerified = response['Items'][0]['isVerified']
                timestamp = response['Items'][0]['timestamp']
                email = response['Items'][0]['email']

                if (isVerified == 0):
                    return HttpResponseRedirect('/accounts/verifyotp/')

                if (datetime.strptime(timestamp, "%Y%m%d%H%M%S") +
                        timedelta(days=7) < datetime.now()):
                    table.delete(FilterExpression={
                        'session_key': args[0].session['session_key']
                    })
                    del args[0].session['session_key']
                    return HttpResponseRedirect("/accounts/login/")

                if (isDoctor0 == isDoctor):
                    return function(*args, **kwargs)

            return HttpResponseRedirect("/accounts/login/")
Beispiel #3
0
def med_list(request):
    if is_authenticated != 0:
        table = Table('med')
        res = table.scan(FilterExpression={}).values()
        if request.method == "GET":
            for i in res['Items']:
                i['_id'] = str(i['_id'])
            return Response(res)

        elif request.method == 'POST':
            med_data = request.data
            if med_data['method'] == 'get_medications':
                res = table.scan(FilterExpression={
                    'med_id': med_data['med_id']
                }).values()
                for i in res['Items']:
                    i['_id'] = str(i['_id'])
                return Response(res)
            elif med_data['method'] == 'add_medications':
                for id in res['Items']:
                    # print(id, type(id))
                    mid = id['med_id']
                mid = int(mid) + 1
                table.insertValues(values=[{
                    'med_id': str(mid),
                    'med': med_data['med']
                }])
                return HttpResponse("Added Medicines")
            elif med_data['method'] == 'delete_medcations':
                table.delete(FilterExpression={'med_id': med_data['med_id']})
                return HttpResponse("Deleted that slot id")
Beispiel #4
0
def logoutD(request):
    if 'session_key' in request.session:
        table = Table('SessionStore')
        table.delete(
            FilterExpression={'session_key': request.session['session_key']})
        del request.session['session_key']
    return HttpResponse("LOGED OUT")
Beispiel #5
0
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')
        
        
        
        
        
        
        
        
        
        
        
        
Beispiel #6
0
def verifyotp(request):
    email = getEmail(request.session['session_key'])
    if request.method == "GET":
        table = Table('otp')
        response = table.scan(FilterExpression={'email': email}).values()

        if response['Count'] == 0:
            sendOtp(email, 1)

        else:
            for x in response['Items']:
                date_time = datetime.strptime(x['timestamp'], "%Y%m%d%H%M%S")
                is4verify = 1 if 'isRegister' in x else 0
                if datetime.now() > date_time + timedelta(minutes=15):
                    sendOtp(email, 1)
                    table.delete(FilterExpression={'otp': x['otp']})
                    break
                if is4verify == 0:
                    sendOtp(email, 1)
        return render(request, 'accounts/verification.html')

    if request.method == "POST":
        form = OTPVerificationForm(request.POST)
        if form.is_valid():
            generatedotp = form.cleaned_data['o1'] + form.cleaned_data[
                'o2'] + form.cleaned_data['o3'] + form.cleaned_data[
                    'o4'] + form.cleaned_data['o5'] + form.cleaned_data['o6']
            generatedotp = hashlib.sha256(
                (generatedotp + SECRET_KEY).encode()).hexdigest()
            table = Table('otp')
            response = table.scan(FilterExpression={
                'otp': generatedotp
            }).values()

            if response['Count'] == 1:
                if response['Items'][0]['otp'] == generatedotp:
                    table.delete(FilterExpression={
                        'otp': generatedotp,
                    })

                    table0 = Table('users')
                    print("has Updated")
                    table0.update(
                        FilterExpression={
                            'email': email,
                        },
                        UpdateExpression={
                            "isVerified": 1,
                        },
                    )
                    del request.session['session_key']
                    return HttpResponseRedirect('/accounts/login/')
                return render(request, 'accounts/verification.html',
                              {'err': 'OTP not match'})
            return HttpResponseRedirect('/accounts/login/')
Beispiel #7
0
def cancel_appointments(request):
    table = Table('appointments')

    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={'app_id': id})
    response = redirect('/appointments/check_app/')
    return response
Beispiel #8
0
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
Beispiel #9
0
def create_doc(request):
    table = Table('slots')
    table.delete()
    fake = Faker()
    for i in range(1, 1001):
        doc = fake.email()
        lat = str(fake.latitude())
        lon = str(fake.longitude())
        fees = random.randint(100, 1000)
        special = [
            'Allergists', 'Anesthesiologists', 'Cardiologists',
            'Dermatologists', 'Endocrinologists', 'FamilyPhysicians',
            'Gastroenterologists', 'Hematologists',
            'InfectiousDiseaseSpecialists', 'Internists', 'MedicalGeneticists',
            'Nephrologists', 'Neurologists', 'Obstetricians', 'Gynecologists',
            'Oncologists', 'Ophthalmologists', 'Osteopaths',
            'Otolaryngologists', 'Pathologists', 'Pediatricians',
            'Physiatrists', 'PlasticSurgeons', 'Podiatrists',
            'PreventiveMedicineSpecialists', 'Psychiatrists', 'Pulmonologists',
            'Radiologists', 'Rheumatologists', 'GeneralSurgeons', 'Urologists'
        ]
        s_rand = random.randint(0, 30)
        spec = special[s_rand]
        th1 = random.randint(0, 23)
        th2 = (th1 + 2) % 24
        t1 = str(th1) + "00"
        t2 = str(th2) + "00"
        dow = ['mon', 'tue', 'wed', 'thu', 'fri']
        r = random.random()
        if r >= 0.8:
            dow.append('sat')
        if r >= 0.9:
            dow.append('sun')
        table.insertValues(values=[{
            'slot_id': str(i),
            'doc_id': doc,
            'spec': spec,
            'start_time': t1,
            'end_time': t2,
            'fees': fees,
            # 'days': dow,
            'lon': lon,
            'lat': lat
        }])
    return HttpResponse("You have generated data")
Beispiel #10
0
def appoint_list(request):
    if is_authenticated != 0:
        table = Table('appointments')
        res = table.scan(FilterExpression={}).values()
        if request.method == "GET":
            for i in res['Items']:
                i['_id'] = str(i['_id'])
            return Response(res)

        elif request.method == 'POST':
            appoint_data = request.data
            if appoint_data['method'] == 'get_appointments':
                res = table.scan(FilterExpression={
                    'doc_id': appoint_data['doc_id']
                }).values()
                for i in res['Items']:
                    i['_id'] = str(i['_id'])
                return Response(res)
            elif appoint_data['method'] == 'add_appointments':
                for id in res['Items']:
                    # print(id, type(id))
                    aid = id['app_id']
                aid = int(aid) + 1
                table.insertValues(
                    values=[{
                        'app_id': str(aid),
                        'doc_id': appoint_data['doc_id'],
                        'spec': appoint_data['spec'],
                        'pat_id': appoint_data['pat_id'],
                        'start_time': appoint_data['start_time'],
                        'end_time': appoint_data['end_time'],
                        'fees': appoint_data['fees'],
                        'date': appoint_data['date']
                    }])
                return HttpResponse("Added Appointments")
            elif appoint_data['method'] == 'delete_appointments':
                table.delete(
                    FilterExpression={'app_id': appoint_data['app_id']})
                return HttpResponse("Deleted that slot id")
Beispiel #11
0
def pres_table_list(request):
    if is_authenticated != 0:
        table = Table('pres_table')
        res = table.scan(FilterExpression={}).values()
        if request.method == "GET":
            for i in res['Items']:
                i['_id'] = str(i['_id'])
            return Response(res)

        elif request.method == 'POST':
            pres_table_data = request.data
            if pres_table_data['method'] == 'get_prescriptions':
                res = table.scan(FilterExpression={
                    'app_id': pres_table_data['app_id']
                }).values()
                for i in res['Items']:
                    i['_id'] = str(i['_id'])
                return Response(res)
            elif pres_table_data['method'] == 'add_prescriptions':
                for id in res['Items']:
                    # print(id, type(id))
                    pid = id['app_id']
                pid = int(pid) + 1
                table.insertValues(
                    values=[{
                        'app_id': str(pid),
                        'doc_id': pres_table_data['doc_id'],
                        'pat_id': pres_table_data['pat_id'],
                        'symptoms': pres_table_data['symptoms'],
                        'notes': pres_table_data['notes'],
                        'tabs': pres_table_data['tabs']
                    }])
                return HttpResponse("Added prescription")
            elif pres_table_data['method'] == 'delete_prescriptions':
                table.delete(
                    FilterExpression={'app_id': pres_table_data['app_id']})
                return HttpResponse("Deleted that slot id")
Beispiel #12
0
def slots_list(request):
    if is_authenticated != 0:
        table = Table('slots')
        res = table.scan(FilterExpression={}).values()
        if request.method == "GET":
            for i in res['Items']:
                i['_id'] = str(i['_id'])
            return Response(res)

        elif request.method == 'POST':
            slots_data = request.data
            # print(slots_data)
            if slots_data['method'] == "get_slots":
                res = table.scan(FilterExpression={
                    'spec': slots_data['spec']
                }).values()
                for i in res['Items']:
                    i['_id'] = str(i['_id'])
                return Response(res)

            elif slots_data['method'] == "add_slots":
                d1 = table.scan(
                    FilterExpression={
                        'doc_id': slots_data['doc_id'],
                        'spec': slots_data['spec'],
                        'lon': slots_data['lon'],
                        'lat': slots_data['lat']
                    }).values()
                if d1['Count'] == 0:
                    l = slots_data['doc_id']
                    sid = 0
                    for i in res['Items']:
                        if int(i['slot_id'][l:]) > sid:
                            sid = i['slot_id'][l:]
                    sid = int(sid) + 1
                    table.insertValues(
                        values=[{
                            'slot_id': slots_data['doc_id'] + str(sid),
                            'doc_id': slots_data['doc_id'],
                            'spec': slots_data['spec'],
                            'start_time': slots_data['start_time'],
                            'end_time': slots_data['end_time'],
                            'fees': slots_data['fees'],
                            'days': slots_data['days'],
                            'lon': slots_data['lon'],
                            'lat': slots_data['lat']
                        }])
                    return HttpResponse("Added new value")
                else:
                    for item in d1['Items']:
                        sst = int(slots_data['start_time'])
                        snt = int(slots_data['end_time'])
                        ist = int(item['start_time'])
                        iet = int(item['end_time'])
                        if ist < sst < iet:
                            return HttpResponse(
                                "New slot can't be created due to clashing of slot times"
                            )
                        elif ist < snt < iet:
                            return HttpResponse(
                                "New slot can't be created due to clashing of slot times"
                            )
                        elif (sst == ist) & (snt == iet):
                            return HttpResponse(
                                "New slot can't be created due to clashing of slot times"
                            )
                        else:
                            l = slots_data['doc_id']
                            sid = 0
                            for i in res['Items']:
                                if int(i['slot_id'][l:]) > sid:
                                    sid = i['slot_id'][l:]
                            sid = int(sid) + 1
                            table.insertValues(values=[
                                {
                                    'slot_id': slots_data['doc_id'] + str(sid),
                                    'doc_id': slots_data['doc_id'],
                                    'spec': slots_data['spec'],
                                    'start_time': slots_data['start_time'],
                                    'end_time': slots_data['end_time'],
                                    'fees': slots_data['fees'],
                                    'days': slots_data['days'],
                                    'lon': slots_data['lon'],
                                    'lat': slots_data['lat']
                                }
                            ])
                            return HttpResponse("Added new value")

            elif slots_data['method'] == "delete_slots":
                table.delete(
                    FilterExpression={'slot_id': slots_data['slot_id']})
                return HttpResponse("Deleted that slot id")
Beispiel #13
0
def changePassword(request):
    if request.method == "GET":
        if 'tk' in request.GET:
            tk = request.GET['tk']
            tk = tk.encode('utf-8')
            jdata = jwt.decode(tk, SECRET_KEY, algorithms=['HS256'])

            if 'timestamp' not in jdata or 'email' not in jdata or 'signature' not in jdata:
                return render(request, 'global/400.html')

            if datetime.strptime(
                    jdata['timestamp'],
                    "%Y%m%d%H%M%S") + timedelta(minutes=5) < datetime.now():
                return render(request, 'global/400.html')

            email = jdata['email']
            timestamp0 = jdata['timestamp']
            signature = jdata['signature']
            genSignature = hashlib.sha256(
                (email + timestamp0 + SECRET_KEY).encode()).hexdigest()
            if signature != genSignature:
                return render(request, 'global/400.html')
            table = Table('forgototpsignatures')
            resp = table.scan(FilterExpression={
                'signature': signature
            }).values()

            if resp['Count'] != 1:
                return render(request, 'global/400.html')
            return render(request, 'accounts/change_password.html',
                          {'tk': tk.decode('utf-8')})
        return render(request, 'global/400.html')

    if request.method == "POST":
        form = ChangePasswordForm(request.POST)
        err = ""
        if form.is_valid():
            tk = form.cleaned_data['tk']
            paswd = form.cleaned_data['new_paswd']
            cpaswd = form.cleaned_data['cnfrm_paswd']
            if isvalidPassword(paswd) == False or isvalidPassword(
                    cpaswd) == False:
                err += "password should contain one Capital letter on small letter and one Number"
            if cpaswd != paswd:
                err += "password not matched"

            if err == "":
                tk = tk.encode('utf-8')
                jdata = jwt.decode(tk, SECRET_KEY, algorithms=['HS256'])

                if 'timestamp' not in jdata or 'email' not in jdata or 'signature' not in jdata:
                    return render(request, 'global/400.html')

                if datetime.strptime(jdata['timestamp'], "%Y%m%d%H%M%S"
                                     ) + timedelta(minutes=5) < datetime.now():
                    return render(request, 'global/400.html')

                email = jdata['email']
                timestamp0 = jdata['timestamp']
                signature = jdata['signature']
                genSignature = hashlib.sha256(
                    (email + timestamp0 + SECRET_KEY).encode()).hexdigest()
                if signature != genSignature:
                    return render(request, 'global/400.html')
                table = Table('forgototpsignatures')
                resp = table.scan(FilterExpression={
                    'signature': signature
                }).values()
                if resp['Count'] != 1:
                    return render(request, 'global/400.html')
                table.delete(FilterExpression={'signature': signature})
                hasedpassword = hashlib.sha256(
                    (paswd + SECRET_KEY).encode()).hexdigest()
                table = Table('users')
                table.update(
                    FilterExpression={'email': email},
                    UpdateExpression={'password': hasedpassword},
                )
                return HttpResponse("Password Changed Successfully")
            return render(request, 'accounts/change_password.html', {
                'err': err,
                'tk': tk
            })
        return render(request, 'accounts/change_password.html', {'err': err})