Exemplo n.º 1
0
def users_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request,
                                                       [Account.ACCOUNT_ADMIN])
    if authentication_result is not None:
        return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(request)
    # Proceed with the rest of the view
    if request.method == 'POST':
        pk = request.POST['pk']
        role = request.POST['role']
        account = Account.objects.get(pk=pk)
        if account is not None:
            account.role = role
            account.save()
            logger.log(Action.ACTION_ADMIN,
                       'Admin modified ' + account.user.username + "'s role",
                       request.user.account)
            template_data[
                'alert_success'] = "Updated" + account.user.username + "'s role!"
    # Parse search sorting
    template_data['query'] = Account.objects.filter(
        archive=False).order_by('-role')
    return render(request, 'virtualclinic/admin/users.html', template_data)
Exemplo n.º 2
0
def csv_import_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN])
    if authentication_result is not None: return authentication_result
    template_data = views.parse_session(request, {'form_button': "Submit"})
    if request.method=='POST':
        form = ImportForm(request.POST, request.FILES)
        if form.is_valid():
            file = request.FILES['upload']
            for line in file:
                first_word = re.split('[,]',line.decode("utf-8").strip())[0].lower()
                if first_word == 'firstname':
                    count = handle_user_csv(file)
                    m = str(count[0])+' users are successfully uploaded, '+str(count[1])+' duplicate accounts.'
                    if count[0] == 0:
                        template_data['alert_danger'] = m
                    else:
                        template_data['alert_success'] = m
                elif first_word=='name':
                    count = handle_hospital_csv(file)
                    m = str(count[0])+' hospitals are successfully uploaded, '+str(count[1])+' duplicate hospitals.'
                    if count[0] == 0:
                        template_data['alert_danger'] = m
                    else:
                        template_data['alert_success'] = m
                else:
                    template_data['alert_danger'] = "Invalid CSV format."
                template_data['form'] = form
                return render(request,'virtualclinic/admin/import.html', template_data)
        else:
            template_data['alert_danger'] = "Please choose a file to upload"
    form = ImportForm()
    template_data['form'] = form
    return render(request,'virtualclinic/admin/import.html',template_data)
Exemplo n.º 3
0
def add_hospital_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request,
                                                       [Account.ACCOUNT_ADMIN])
    if authentication_result is not None: return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(request,
                                        {'form_button': "Add Hospital"})
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = HospitalForm(request.POST)
        if form.is_valid():
            location = location(city=form.cleaned_data['city'],
                                zip=form.cleaned_data['zip'],
                                state=form.cleaned_data['state'],
                                address=form.cleaned_data['address'])
            location.save()
            hospital = Hospital(
                name=form.cleaned_data['name'],
                phone=form.cleaned_data['phone'],
                location=location,
            )
            hospital.save()
            form = HospitalForm()  # Clean the form when page is redisplayed
            template_data['alert_success'] = "Successfully added the hospital!"
    else:
        form = HospitalForm()
    template_data['form'] = form
    return render(request, 'virtualclinic/admin/add_hospital.html',
                  template_data)
Exemplo n.º 4
0
def add_symptom(request):
    # Authentication check
    authentication_result = views.authentication_check(request,
                                                       [Account.ACCOUNT_ADMIN])
    if authentication_result is not None:
        return authentication_result
    # Get template data from the session
    template_data = views.parse_session(request,
                                        {'form_button': "Add Symptom"})
    #parse_speciality_delete(request, template_data)  # parse appointment cancelling
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = SymptomForm(request.POST)
        if form.is_valid():
            symptom = Symptom(name=form.cleaned_data['name'],
                              description=form.cleaned_data['description'])
            symptom.save()
            form = SymptomForm()  # Clean the form when page is redisplayed
            template_data['alert_success'] = "Successfully added the Symptom!"
            logger.log(Action.ACTION_ADMIN, 'Admin added ' + symptom.name,
                       request.user.account)
            return HttpResponseRedirect('/admin/symptom')
    else:
        form = SymptomForm()
    template_data['form'] = form
    return render(request, 'virtualclinic/admin/add_symptom.html',
                  template_data)
Exemplo n.º 5
0
def register_view(request):
    # Authentication check. Users logged in cannot view this page.
    if request.user.is_authenticated:
        return HttpResponseRedirect('/profile/')
    elif Account.objects.all().count() == 0:
        return HttpResponseRedirect('/setup/')
    # Get template data from session
    template_data = views.parse_session(request, {'form_button': "Register"})
    # Proceed with rest of the view
    if request.method == 'POST':
        form = AccountRegisterForm(request.POST)
        if form.is_valid():
            views.register_user(
                form.cleaned_data['email'],
                form.cleaned_data['password_first'],
                form.cleaned_data['firstname'],
                form.cleaned_data['lastname'],
                # form.cleaned_data['speciality'],
                Account.ACCOUNT_PATIENT)
            user = authenticate(username=form.cleaned_data['email'].lower(),
                                password=form.cleaned_data['password_first'])
            logger.log(Action.ACTION_ACCOUNT, "Account Login", user.account)
            login(request, user)
            request.session[
                'alert_success'] = "Successfully registered with VirtualClinic."
            return HttpResponseRedirect('/profile/')
    else:
        form = AccountRegisterForm()
    template_data['form'] = form
    return render(request, 'virtualclinic/register.html', template_data)
Exemplo n.º 6
0
def create_view(request):
    # Authentication check
    authentication_result = views.authentication_check(
        request,
        [Account.ACCOUNT_DOCTOR, Account.ACCOUNT_LAB]
    )
    if authentication_result is not None:
        return authentication_result
    # get template data from session
    template_data = views.parse_session(request, {'form_button': "Upload"})
    # proceed with rest of the view
    default = {}
    if request.user.account.role == Account.ACCOUNT_DOCTOR:
        default['doctor'] = request.user.account.pk
    if 'hospital' not in request.POST and request.user.account.profile.prefHospital is not None:
        default['hospital'] = request.user.account.profile.prefHospital.pk
    if 'date' not in request.POST:
        default['date'] = datetime.now().strftime("%Y-%m-%d")
    request.POST._mutable = True
    request.POST.update(default)
    form = MedTestForm(request.POST,request.FILES)
    if request.method == 'POST':
        if form.is_valid():
            medicaltest = form.generate()
            medicaltest.save()
            logger.log(Action.ACTION_MEDTEST,'Medical Test Created', request.user.account)
            form = MedTestForm(default)  # clean form data
            #form.disable_field('doctor')
            form._errors = {}
            template_data['alert_success'] = "Successfully uploaded medical test"
    else:
        form._errors = {}
    #form.disable_field('doctor')
    template_data['form'] = form
    return render(request,'virtualclinic/medtest/upload.html', template_data)
Exemplo n.º 7
0
def update_asset(request):
    # Authentication check
    authentication_result = views.authentication_check(request, None, ['pk'])
    if authentication_result is not None:
        return authentication_result

    pk = request.GET['pk']
    a = asset()
    try:
        Asset = asset.objects.get(pk=pk)
        print(Asset)
    except Exception:
        request.session['alert_danger'] = "The requested image doesn't exist"
        return HttpResponseRedirect('/error/denied')
    template_data = views.parse_session(
        request, {
            'form_button': "Update image asset",
            'form_action': "?pk=" + pk,
            'asset': Asset
        })
    request.POST._mutable = True
    if request.method == 'POST':
        form = AssetForm(request.POST)
        if form.is_valid():
            form.assign(Asset)
            Asset.save()
            template_data['alert_success'] = "The asset data has been updated!"
            template_data['form'] = form
    else:
        form = AssetForm(Asset.get_populated_fields())
    template_data['form'] = form
    return render(request, 'asset_update.html', template_data)
Exemplo n.º 8
0
def createemployee_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request,
                                                       [Account.ACCOUNT_ADMIN])
    if authentication_result is not None: return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(request, {'form_button': "Register"})
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = EmployeeRegistrationForm(request.POST)
        if form.is_valid():
            user = views.register_user(form.cleaned_data['email'],
                                       form.cleaned_data['password_first'],
                                       form.cleaned_data['firstname'],
                                       form.cleaned_data['lastname'],
                                       form.cleaned_data['employee'],
                                       form.cleaned_data['speciality'])
            logger.log(Action.ACTION_ADMIN,
                       'Admin registered ' + user.username,
                       request.user.account)
            request.session[
                'alert_success'] = "Successfully created new employee account"
            return HttpResponseRedirect('/admin/users/')
    else:
        form = EmployeeRegistrationForm()
    template_data['form'] = form
    return render(request, 'virtualclinic/admin/createemployee.html',
                  template_data)
def setup_view(request):
    if Account.objects.all().count() > 0:
        request.session['alert_success'] = "Setup has already been completed."
        return HttpResponseRedirect('/')
    # Get template data from the session
    template_data = views.parse_session(request, {'form_button': "Register"})
    # Proceed with rest of the view
    if request.method == 'POST':
        form = AccountRegisterForm(request.POST)
        if form.is_valid():
            views.register_user(form.cleaned_data['email'],
                                form.cleaned_data['password_first'],
                                form.cleaned_data['firstname'],
                                form.cleaned_data['lastname'],
                                Account.ACCOUNT_ADMIN)
            user = authenticate(
                username=form.cleaned_data['email'].lower(
                ),  # Make sure it's lowercase
                password=form.cleaned_data['password_first'])
            logger.log(Action.ACTION_ACCOUNT, "Account login", user.account)
            login(request, user)
            request.session[
                'alert_success'] = "Successfully setup Virtual Clinic's primary admin account."
            return HttpResponseRedirect('/profile/')
    else:
        form = AccountRegisterForm()
    template_data['form'] = form
    return render(request, 'virtualclinic/setup.html', template_data)
Exemplo n.º 10
0
def new_view(request):
    # Authentication Check
    authentication_result = views.authentication_check(request)
    if authentication_result is not None:
        return authentication_result
    # Get template data from session
    template_data = views.parse_session(request,
                                        {'form_button': "Send Message"})
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = MessageForm(request.POST)
        if form.is_valid():
            message = form.generate(request.user.account)
            message.save()
            logger.log(Action.ACTION_MESSAGE, 'Message Sent',
                       request.user.account)
            request.session[
                'alert_success'] = "Successfully sent your message!"
            return HttpResponseRedirect('/message/list')
    else:
        # Validation Check. Make sure a message exists for the given pk.
        default = {}
        if 'pk' in request.GET:
            pk = request.GET['pk']
            try:
                account = Account.objects.get(pk=pk)
                default['target'] = pk
            except Exception:
                template_data[
                    'alert_danger'] = "We couldn't find your the person you're replying to. Please try again"

        form = MessageForm(default)
        form.clear_errors()
    template_data['form'] = form
    return render(request, 'virtualclinic/message/new.html', template_data)
def login_view(request):
    # Authentication check. Users currently logged in cannot view this page.
    if request.user.is_authenticated:
        return HttpResponseRedirect('/profile/')
    elif Account.objects.all().count() == 0:
        return HttpResponseRedirect('/setup/')
    # get template data from session
    template_data = views.parse_session(request, {'form_button': "Login"})
    # Proceed with the rest of view
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(username=form.cleaned_data['email'].lower(),
                                password=form.cleaned_data['password'])
            userInfo = Account.objects.get(user=user)
            if userInfo.archive == False:
                login(request, user)
                logger.log(Action.ACTION_ACCOUNT, "Account login",
                           request.user.account)
                request.session[
                    'alert_success'] = "Successfully logged into VirtualClinic."
                return HttpResponseRedirect('/profile/')
            else:
                request.session[
                    'alert_danger'] = "Account is archived! Please create a new account"
                return HttpResponseRedirect('/register/')
    else:
        form = LoginForm()
    template_data['form'] = form
    return render(request, 'virtualclinic/login.html', template_data)
Exemplo n.º 12
0
def assets_view(request):
    authentication_result = views.authentication_check(request)
    if authentication_result is not None:
        return authentication_result
    template_data = views.parse_session(request)
    template_data['assets'] = asset.objects.filter(owner=request.user)
    print(template_data['assets'])
    return render(request, 'assets.html', template_data)
Exemplo n.º 13
0
def profile_view(request):
    # Authentication check
    authentication_result = views.authentication_check(request)
    if authentication_result is not None:
        return authentication_result
    # Get template data from session
    template_data = views.parse_session(request)
    # Proceed with rest of the view
    return render(request, 'profile.html', template_data)
Exemplo n.º 14
0
def view_symptom(request):
    # Authentication check.
    authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN])
    if authentication_result is not None: return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(request)
    # Proceed with the rest of the view
    template_data['query'] = Symptom.objects.all()
    return render(request, 'virtualclinic/admin/symptoms.html', template_data)
def error_denied_view(request):
    # Authentication check
    authentication_result = views.authentication_check(request)
    if authentication_result is not None:
        return authentication_result
    # Get template data from session
    template_data = views.parse_session(request)
    # Proceed with rest of the view
    return render(request, 'virtualclinic/error/denied.html', template_data)
Exemplo n.º 16
0
def view_archived_users(request):
    # Authentication check.
    authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN])
    if authentication_result is not None:
        return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(request)
    # Proceed with the rest of the view
    template_data['query'] = Account.objects.filter(archive=True)
    return render(request, 'virtualclinic/admin/archived_users.html', template_data)
Exemplo n.º 17
0
def activity_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN])
    if authentication_result is not None: return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(request)
    # Proceed with the rest of the view
    # Parse search sorting
    template_data['query'] = Action.objects.all().order_by('-timePerformed')
    return render(request,'virtualclinic/admin/activity.html',template_data)
Exemplo n.º 18
0
def list_view(request):
    # Authentication check
    authentication_result = views.authentication_check(
        request, [Account.ACCOUNT_DOCTOR])
    if authentication_result is not None:
        return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(request)
    # Proceed with rest of the view
    template_data['query'] = MedicalInfo.objects.filter(
        account__role=Account.ACCOUNT_PATIENT)
    return render(request, 'virtualclinic/medicalinfo/list.html',
                  template_data)
Exemplo n.º 19
0
def statistic_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN])
    if authentication_result is not None: return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(request, {'form_button': "Get Statistics"})
    # Proceed with the rest of the view
    default = {}
    request.POST._mutable = True
    request.POST.update(default)
    predate_filter = Action.objects.all()
    template_data['pre_filter'] = predate_filter.count()
    form = StatisticsForm(request.POST)
    if request.method == 'POST':
        if form.is_valid():
            statistics = Statistics(
                startDate = form.cleaned_data['startDate'],
                endDate = form.cleaned_data['endDate'],
            )
            date_filter = Action.objects.all().filter(timePerformed__range = (statistics.startDate,statistics.endDate))
            template_data['temp'] = date_filter.count()
            template_data['start'] = statistics.startDate
            template_data['end'] = statistics.endDate

            template_data['total_logins'] = Action.objects.filter(description__icontains="Account login",timePerformed__range = (statistics.startDate, statistics.endDate) ).count()
            template_data['total_logouts'] = Action.objects.filter(description__icontains="Account logout",timePerformed__range = (statistics.startDate, statistics.endDate)).count()
            template_data['total_appointments'] = Action.objects.filter(description__icontains="Appointment created",timePerformed__range = (statistics.startDate, statistics.endDate)).count()
            template_data['total_med_tests'] = Action.objects.filter(description__icontains="Medical Test created",timePerformed__range = (statistics.startDate, statistics.endDate)).count()
            template_data['total_registered'] = Action.objects.filter(description__icontains="registered",timePerformed__range = (statistics.startDate, statistics.endDate)).count()

    else:
        form._errors = {}
        statistics = Statistics(
                startDate = 0,
                endDate = 0,
            )
        errdate_filter = Action.objects.all()
        template_data['errdate_filter'] = errdate_filter.count()
        template_data['start'] = statistics.startDate
        template_data['end'] = statistics.endDate

        template_data['total_logins'] = 0
        template_data['total_logouts'] = 0
        template_data['total_appointments'] = 0
        template_data['total_med_tests'] = 0
        template_data['total_registered'] = 0
    template_data['form'] =form

    return render(request,'virtualclinic/admin/statistics.html', template_data)
Exemplo n.º 20
0
def list_view(request):
    # Authentication Check
    authentication_result = views.authentication_check(request)
    if authentication_result is not None:
        return authentication_result
    # Get template data from session
    template_data = views.parse_session(request)
    # Proceed with the rest of the view
    # Parse search sorting
    message.parse_message_archive(request, template_data)
    template_data['messages'] = Message.objects.filter(
        Q(target=request.user.account) | Q(sender=request.user.account))
    template_data['account'] = sanitize_js(
        request.user.account.profile.__str__())
    return render(request, 'virtualclinic/message/list.html', template_data)
Exemplo n.º 21
0
def csv_export_view(request):
    # Authentication check
    authentication_result = views.authentication_check(request,[Account.ACCOUNT_ADMIN])
    if authentication_result is not None:
        return authentication_result
    template_data = views.parse_session(request,{'form_button':"Submit"})
    if request.method == 'POST':
        if request.POST['export'] == 'hospitals':
            return generate_hospital_csv()
        elif request.POST['export'] == 'users':
            return generate_user_csv()
        else:
            template_data['alert_danger'] = 'Please choose a file to download'
    template_data['form'] = ExportForm()
    return render(request,'virtualclinic/admin/export.html', template_data)
Exemplo n.º 22
0
def calendar_view(request):
    # Authentication check
    authentication_result = views.authentication_check(
        request, [Account.ACCOUNT_PATIENT, Account.ACCOUNT_DOCTOR])
    if authentication_result is not None:
        return authentication_result
    # Get template data from session
    template_data = views.parse_session(request)
    # Proceed with rest of the view
    appointment.parse_appointment_cancel(
        request, template_data)  # parse appointment cancelling
    template_data['events'] = appointment.parse_appointments(
        request)  # Build list of appointments
    return render(request, 'virtualclinic/appointment/calendar.html',
                  template_data)
Exemplo n.º 23
0
def display_view(request):
    # Authentication check
    authentication_result = views.authentication_check(
        request,
        None,
        ['pk']
    )
    if authentication_result is not None:
        return authentication_result
    # Validation check. Make sure a medical test exists for given pk
    pk = request.GET['pk']
    try:
        medicaltest = MedicalTest.objects.get(pk=pk)
    except Exception:
        request.session['alert_danger'] = "The requested medical test does not exist"
        return HttpResponseRedirect('/error/denied/')
    # get template data from the session
    template_data = views.parse_session(
        request,
        {
            'form_button': "Return to list of Medical Tests",
            'form_action': "?pk="+pk,
            'medtest' : medicaltest
        })
    # Proceed with the rest of view
    if request.method == 'GET':
        form = MedTestDisplayForm(medicaltest.get_populated_fields())
        form.disable_field('name')
        form.disable_field('date')
        form.disable_field('hospital')
        form.disable_field('description')
        form.disable_field('doctor')
        form.disable_field('patient')
        form.disable_field('private')
        form.disable_field('completed')

        template_data['form'] = form

        template_data['img'] = medicaltest.image1
        template_data['img2'] = medicaltest.image2
        template_data['img3'] = medicaltest.image3
        template_data['img4'] = medicaltest.image4
        template_data['img5'] = medicaltest.image5
    else:
        return HttpResponseRedirect('/medtest/list')
    return render(request, 'virtualclinic/medtest/display.html', template_data)
Exemplo n.º 24
0
def update_view(request):
    # Authentication check
    authentication_result = views.authentication_check(
        request,
        [Account.ACCOUNT_PATIENT, Account.ACCOUNT_DOCTOR, Account.ACCOUNT_LAB])
    if authentication_result is not None:
        return authentication_result
    # Validation Check. Make sure an appointment exists for the given pk.
    if 'pk' in request.GET:
        if request.user.account.role != Account.ACCOUNT_DOCTOR:
            request.session[
                'alert_danger'] = "You don't have permission to view the page."
            return HttpResponseRedirect('/error/denied/')
        pk = request.GET['pk']
        try:
            medicalinfo = MedicalInfo.objects.get(pk=pk)
        except Exception:
            request.session[
                'alert_danger'] = "The requested medical info doesn't exist."
            return HttpResponseRedirect('/error/denied/')
    else:
        medicalinfo = MedicalInfo.objects.get(account=request.user.account)
    # Get template data from the session
    template_data = views.parse_session(request,
                                        {'form_button': "Update Medical Info"})
    if 'pk' in request.GET:
        template_data['form_action'] = "?pk=" + pk
    # Proceed with rest of the view
    request.POST._mutable = True
    request.POST['account'] = medicalinfo.account.pk
    if request.method == 'POST':
        form = MedicalInfoForm(request.POST)
        if form.is_valid():
            form.assign(medicalinfo)
            medicalinfo.save()
            logger.log(Action.ACTION_MEDICALINFO, 'Medical Info Updated',
                       request.user.account)
            template_data[
                'alert_success'] = "The medical info has been updated"
    else:
        form = MedicalInfoForm(medicalinfo.get_populated_fields())
    template_data['form'] = form
    form.disable_field('account')
    return render(request, 'virtualclinic/medicalinfo/update.html',
                  template_data)
Exemplo n.º 25
0
def create_view(request):
    # Authentication Check
    authentication_result = views.authentication_check(
        request, [Account.ACCOUNT_DOCTOR])
    if authentication_result is not None:
        return authentication_result
    # Get template data from session
    template_data = views.parse_session(request,
                                        {'form_button': "Add Prescription"})
    default = {}
    if request.user.account.role == Account.ACCOUNT_DOCTOR:
        default['doctor'] = request.user.account.pk
    if 'date' not in request.POST:
        default['date'] = datetime.now().strftime("%Y-%m-%d")
    request.POST._mutable = True
    request.POST.update(default)
    form = PrescriptionForm(request.POST)
    if request.method == 'POST':
        if form.is_valid():
            pres = Prescription(
                patient=form.cleaned_data['patient'],
                doctor=form.cleaned_data['doctor'],
                date=form.cleaned_data['date'],
                medication=form.cleaned_data['medication'],
                strength=form.cleaned_data['strength'],
                instruction=form.cleaned_data['instruction'],
                refill=form.cleaned_data['refill'],
            )
            pres.save()
            logger.log(Action.ACTION_PRESCRIPTION, 'Prescription Created',
                       request.user.account)
            form = PrescriptionForm(
                default)  # Clean form data when page is redisplayed
            form._errors = {}
            request.session[
                'alert_success'] = "Successfully added the prescription."
            return HttpResponseRedirect('/prescription/list/')
    else:
        form._errors = {}
    if request.user.account.role == Account.ACCOUNT_DOCTOR:
        form.disable_field('doctor')
        form.date = datetime.today()
    template_data['form'] = form
    return render(request, 'virtualclinic/prescription/create.html',
                  template_data)
Exemplo n.º 26
0
def list_view(request):
    # Authentication check
    authentication_result = views.authentication_check(
        request,
        [Account.ACCOUNT_DOCTOR, Account.ACCOUNT_PATIENT, Account.ACCOUNT_LAB]
    )
    if authentication_result is not None:
        return authentication_result
    # get template data from session
    template_data = views.parse_session(request)
    # proceed with rest of the view
    if request.user.account.role == Account.ACCOUNT_DOCTOR:
        template_data['query'] = MedicalTest.objects.all()
    elif request.user.account.role == Account.ACCOUNT_LAB:
        template_data['query'] = MedicalTest.objects.all()
    else:
        template_data['query'] = MedicalTest.objects.filter(private=False)
    return render(request, 'virtualclinic/medtest/list.html', template_data)
Exemplo n.º 27
0
def parse_symptom_delete(request):
    # Authentication check.
    authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN])
    if authentication_result is not None:
        return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(request)
    # Proceed with the rest of the view
    if request.method == 'POST':
        if 'delete' in request.POST and 'pk' in request.POST:
            pk = request.POST['pk']
            try:
                symptom = Symptom.objects.get(pk=pk)
            except Exception:
                template_data['alert_danger'] = "Unable to delete the symptom. Please try again later."
                return
            symptom.delete()
            logger.log(Action.ACTION_ADMIN, 'Symptom cancelled', request.user.account)
            template_data['alert_success'] = "The symptom has been deleted."
            return HttpResponseRedirect('/admin/symptom/')
Exemplo n.º 28
0
def list_view(request):
    # Authentication check
    authentication_result = views.authentication_check(
        request, [Account.ACCOUNT_PATIENT, Account.ACCOUNT_DOCTOR])
    if authentication_result is not None:
        return authentication_result
    # Get template data from session
    template_data = views.parse_session(request)
    # Proceed with rest of the view
    appointment.parse_appointment_cancel(
        request, template_data)  # parse appointment cancelling
    if request.user.account.role == Account.ACCOUNT_DOCTOR:
        template_data['query'] = Appointment.objects.filter(
            doctor=request.user.account)
    elif request.user.account == Account.ACCOUNT_PATIENT:
        template_data['query'] = Appointment.objects.filter(
            patient=request.user.account)
    else:
        template_data['query'] = Appointment.objects.all()
    return render(request, 'virtualclinic/appointment/list.html',
                  template_data)
Exemplo n.º 29
0
def user_archive(request):
    # Authentication check.
    authentication_result = views.authentication_check(request, [Account.ACCOUNT_ADMIN])
    if authentication_result is not None:
        return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(request)
    # Proceed with the rest of the view
    if request.method == 'POST':
        if 'delete' in request.POST and 'pk' in request.POST:
            pk = request.POST['pk']
            try:
                user = Account.objects.get(pk=pk)
            except Exception:
                template_data['alert_danger'] = "Unable to delete the user. Please try again later"
                return
            user.archive = True
            user.save()
            #logger.log(Action.ACTION_ADMIN, 'Admin deleted a user',user)
            template_data['alert_success'] = "The user has been deleted."
            return HttpResponseRedirect('/admin/users')
Exemplo n.º 30
0
def restore_user(request):
    # Authentication check.
    authentication_result = views.authentication_check(request,
                                                       [Account.ACCOUNT_ADMIN])
    if authentication_result is not None:
        return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(request)
    # Proceed with the rest of the view
    if request.method == 'POST':
        if 'restore' in request.POST and 'pk' in request.POST:
            pk = request.POST['pk']
            try:
                user = Account.objects.get(pk=pk)
            except Exception:
                template_data[
                    'alert_danger'] = "Unable to delete the user. Please try again later"
                return HttpResponseRedirect('/admin/users')
            user.archive = False
            user.save()
            logger.log(Action.ACTION_ADMIN, 'Admin restored the user', user)

            url = 'https://evoluzy.et.r.appspot.com/patient/'
            x = requests.get(url, params={'patientId': user.profile.id})
            patient_dict = json.loads(x.text)

            url = 'https://evoluzy.et.r.appspot.com/patient/'
            myobj = {
                "patientId": patient_dict['patientId'],
                "isApproved": patient_dict['isApproved'],
                "isArchived": False,
                "patientName": patient_dict['patientName'],
                "healthData": patient_dict['healthData']
            }
            x = requests.put(url, json=myobj)
            print(x.text)

            template_data['alert_success'] = "The user has been restored."
            return HttpResponseRedirect('/admin/users')
    return HttpResponseRedirect('/admin/users')