Пример #1
0
def admit_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request, [
        Account.ACCOUNT_PATIENT, Account.ACCOUNT_NURSE, 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, {'form_button': "Admit"})
    # Proceed with the rest of the view
    default = {}

    request.POST._mutable = True
    request.POST.update(default)
    form = AdmissionForm(request.POST)
    if request.method == 'POST':
        if form.is_valid():
            admiss = Admission(
                patient=form.cleaned_data['patient'].user,
                reason=form.cleaned_data['reason'],
                hospital=form.cleaned_data['hospital'],
                time=form.cleaned_data['time'],
                date=form.cleaned_data['date'],
            )
            admiss.save()
            logger.log(Action.ACTION_ADMISSION, 'Admitted Patient',
                       request.user)
            form = AdmissionForm(
                default)  # Clean the form when the page is redisplayed
            form._errors = {}
            template_data['alert_success'] = "Successfully admitted patient!"
    else:
        form._errors = {}
    template_data['form'] = form
    return render(request, 'docnet/admission/admit.html', template_data)
Пример #2
0
def discharge_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(
        request, [Account.ACCOUNT_DOCTOR], ['pk'])
    if authentication_result is not None: return authentication_result
    # Validation Check. Make sure an admission exists for the given pk.
    pk = request.GET['pk']
    try:
        admission = Admission.objects.get(pk=pk)
    except Exception:
        return HttpResponseRedirect('/error/denied/')
    # Get the template data from the session
    template_data = views.parse_session(request, {
        'admission': admission,
        'form_action': "?pk=" + pk
    })
    # Proceed with the rest of the view
    if request.method == 'POST':
        if 'yes' in request.POST:
            admission.active = False
            admission.save()
            logger.log(Action.ACTION_ADMISSION, 'Discharged Patient',
                       request.user)
            request.session[
                'alert_danger'] = "The patient has been discharged."  # Use session when passing data through a redirect
            return HttpResponseRedirect('/admission/list/')
        elif 'no' in request.POST:
            request.session[
                'alert_success'] = "The patient was not discharged."  # Use session when passing data through a redirect
            return HttpResponseRedirect('/admission/list/')
    return render(request, 'docnet/admission/discharge.html', template_data)
Пример #3
0
def password_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request)
    if authentication_result is not None: return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(request,
                                        {'form_button': "Change password"})
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = PasswordForm(request.POST)
        if form.is_valid():
            user = authenticate(username=request.user.username,
                                password=form.cleaned_data['password_current'])
            if user is None:
                form.mark_error('password_current', 'Incorrect password')
            else:
                user = request.user
                user.set_password(form.cleaned_data['password_first'])
                user.save()
                logger.log(Action.ACTION_ACCOUNT, "Account password change",
                           request.user)
                form = PasswordForm(
                )  # Clean the form when the page is redisplayed
                template_data[
                    'alert_success'] = "Your password has been changed!"
    else:
        form = PasswordForm()
    template_data['form'] = form
    return render(request, 'docnet/profile/password.html', template_data)
Пример #4
0
def delete_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(
        request, [Account.ACCOUNT_DOCTOR], ['pk'])
    if authentication_result is not None: return authentication_result
    # Validation Check. Make sure a prescription exists for the given pk.
    pk = request.GET['pk']
    try:
        prescription = Prescription.objects.get(pk=pk)
    except ObjectDoesNotExist:
        return HttpResponseRedirect('/error/denied/')
    # Get the template data from the session
    template_data = views.parse_session(request, {
        'prescription': prescription,
        'form_action': "?pk=" + pk
    })
    # Proceed with the rest of the view
    if request.method == 'POST':
        if 'yes' in request.POST:
            prescription.active = False
            prescription.save()
            logger.log(Action.ACTION_PRESCRIPTION, 'Prescription Cancelled',
                       request.user)
            request.session[
                'alert_danger'] = "The prescription has been deleted."
            return HttpResponseRedirect('/prescription/list/')
        elif 'no' in request.POST:
            request.session[
                'alert_success'] = "The prescription was not deleted."
            return HttpResponseRedirect('/prescription/list/')
    return render(request, 'docnet/prescription/delete.html', template_data)
Пример #5
0
def cancel_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request, [
        Account.ACCOUNT_PATIENT, Account.ACCOUNT_DOCTOR, Account.ACCOUNT_ADMIN
    ], ['pk'])
    if authentication_result is not None: return authentication_result
    # Validation Check. Make sure an appointment exists for the given pk.
    pk = request.GET['pk']
    try:
        appointment = Appointment.objects.get(pk=pk)
    except Exception:
        return HttpResponseRedirect('/error/denied/')
    # Get the template data from the session
    template_data = views.parse_session(request, {
        'appointment': appointment,
        'form_action': "?pk=" + pk
    })
    # Proceed with the rest of the view
    if request.method == 'POST':
        if 'yes' in request.POST:
            appointment.active = False
            appointment.save()
            logger.log(Action.ACTION_APPOINTMENT, 'Appointment cancelled',
                       request.user)
            request.session[
                'alert_danger'] = "The appointment has been cancelled."  # Use session when passing data through a redirect
            return HttpResponseRedirect('/appointment/list/')
        elif 'no' in request.POST:
            request.session[
                'alert_success'] = "The appointment was not cancelled."  # Use session when passing data through a redirect
            return HttpResponseRedirect('/appointment/list/')
    return render(request, 'docnet/appointment/cancel.html', template_data)
Пример #6
0
def register_view(request):
    # Authentication check. Users logged in cannot view this page.
    if request.user.is_authenticated:
        return HttpResponseRedirect('/profile/')
    # Get the template data from the session
    template_data = parse_session(request, {'form_button': "Register"})
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = AccountRegisterForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                form.cleaned_data['email'].lower(
                ),  # Username, make sure it's lowercase
                form.cleaned_data['email'],  # Email
                form.cleaned_data['password_first']  # Password
            )
            profile = Profile(
                firstname=form.cleaned_data['firstname'],
                lastname=form.cleaned_data['lastname'],
                insurance=form.cleaned_data['insurance'],
            )
            profile.save()
            account = Account(role=Account.ACCOUNT_PATIENT,
                              profile=profile,
                              user=user)
            account.save()
            medicalinfo = MedicalInfo(patient=account.user,
                                      alzheimer=False,
                                      asthma=False,
                                      diabetes=False,
                                      stroke=False)
            medicalinfo.save()
            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 registered", user)
            logger.log(Action.ACTION_ACCOUNT, "Account login", user)
            login(request, user)
            request.session[
                'alert_success'] = "Successfully registered with docnet."
            return HttpResponseRedirect('/profile/')
    else:
        form = AccountRegisterForm()
    template_data['form'] = form
    return render(request, 'docnet/register.html', template_data)
Пример #7
0
def logout_view(request):
    if request.user.is_authenticated:
        logger.log(Action.ACTION_ACCOUNT, "Account logout", request.user)
    # Django deletes the session on logout, so we need to preserve any alerts currently waiting to be displayed
    saved_data = {}
    if request.session.has_key('alert_success'):
        saved_data['alert_success'] = request.session['alert_success']
    else:
        saved_data['alert_success'] = "You have successfully logged out."
    if request.session.has_key('alert_danger'):
        saved_data['alert_danger'] = request.session['alert_danger']
    logout(request)
    if 'alert_success' in saved_data:
        request.session['alert_success'] = saved_data['alert_success']
    if 'alert_danger' in saved_data:
        request.session['alert_danger'] = saved_data['alert_danger']
    return HttpResponseRedirect('/')
Пример #8
0
def create_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request, [
        Account.ACCOUNT_PATIENT, Account.ACCOUNT_NURSE, 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, {'form_button': "Create"})
    # Proceed with the rest of the view
    default = {}
    if request.user.account.role == Account.ACCOUNT_PATIENT:
        default['patient'] = request.user.account.pk
    elif request.user.account.role == Account.ACCOUNT_DOCTOR:
        default['doctor'] = request.user.account.pk
    request.POST._mutable = True
    request.POST.update(default)
    form = AppointmentForm(request.POST)
    if request.method == 'POST':
        if form.is_valid():
            appt = Appointment(
                doctor=form.cleaned_data['doctor'].user,
                patient=form.cleaned_data['patient'].user,
                description=form.cleaned_data['description'],
                hospital=form.cleaned_data['hospital'],
                startTime=form.cleaned_data['startTime'],
                endTime=form.cleaned_data['endTime'],
                date=form.cleaned_data['date'],
            )
            appt.save()
            logger.log(Action.ACTION_APPOINTMENT, 'Appointment created',
                       request.user)
            form = AppointmentForm(
                default)  # Clean the form when the page is redisplayed
            form._errors = {}
            template_data[
                'alert_success'] = "Successfully created your appointment!"
    else:
        form._errors = {}
    if request.user.account.role == Account.ACCOUNT_PATIENT:
        form.disable_field('patient')
    elif request.user.account.role == Account.ACCOUNT_DOCTOR:
        form.disable_field('doctor')
    template_data['form'] = form
    return render(request, 'docnet/appointment/create.html', template_data)
Пример #9
0
def update_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 an appointment exists for the given pk.
    pk = request.GET['pk']
    try:
        appointment = Appointment.objects.get(pk=pk)
    except Exception:
        request.session[
            'alert_danger'] = "The requested appointment does not exist."
        return HttpResponseRedirect('/error/denied/')
    # Get the template data from the session
    template_data = views.parse_session(
        request, {
            'form_button': "Update Appointment",
            'form_action': "?pk=" + pk,
            'appointment': appointment
        })
    # Proceed with the rest of the view
    request.POST._mutable = True
    if request.user.account.role == Account.ACCOUNT_PATIENT:
        request.POST['patient'] = request.user.account.pk
    elif request.user.account.role == Account.ACCOUNT_DOCTOR:
        request.POST['doctor'] = request.user.account.pk
    if request.method == 'POST':
        form = AppointmentForm(request.POST)
        if form.is_valid():
            form.assign(appointment)
            appointment.save()
            logger.log(Action.ACTION_APPOINTMENT, 'Appointment updated',
                       request.user)
            template_data[
                'alert_success'] = "The appointment has been updated!"
            template_data['form'] = form
    else:
        form = AppointmentForm(appointment.get_populated_fields())
    if request.user.account.role == Account.ACCOUNT_PATIENT:
        form.disable_field('patient')
    elif request.user.account.role == Account.ACCOUNT_DOCTOR:
        form.disable_field('doctor')
    template_data['form'] = form
    return render(request, 'docnet/appointment/update.html', template_data)
Пример #10
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 the template data from the session
    template_data = views.parse_session(request, {'form_button': "Upload"})
    # Proceed with the rest of the view
    default = {}
    if request.user.account.role == Account.ACCOUNT_DOCTOR:
        default['doctor'] = request.user.account.pk
    request.POST._mutable = True
    request.POST.update(default)
    form = MedTestForm(request.POST)
    if request.method == 'POST':
        if form.is_valid():
            medtest = MedicalTest(
                name=form.cleaned_data['name'],
                date=form.cleaned_data['date'],
                hospital=form.cleaned_data['hospital'],
                description=form.cleaned_data['description'],
                doctor=form.cleaned_data['doctor'].user,
                patient=form.cleaned_data['patient'].user,
                private=form.cleaned_data['private'],
                completed=form.cleaned_data['completed'],
            )
            medtest.save()
            logger.log(Action.ACTION_MEDTEST, 'Medical Test created',
                       request.user)
            form = MedTestForm(
                default)  # Clean the form when the page is redisplayed
            form.disable_field('doctor')
            form._errors = {}
            template_data[
                'alert_success'] = "Successfully uploaded the medical test!"
    else:
        form._errors = {}
    form.disable_field('doctor')
    # if request.user.account.role == Account.ACCOUNT_DOCTOR:
    # form.disable_field('performedBy')
    template_data['form'] = form
    return render(request, 'docnet/medtest/upload.html', template_data)
Пример #11
0
def update_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request)
    if authentication_result is not None: return authentication_result
    # Get the template data from the asession
    template_data = views.parse_session(request,
                                        {'form_button': "Update profile"})
    # Proceed with the rest of the view
    profile = request.user.account.profile
    if request.method == 'POST':
        form = ProfileForm(request.POST)
        if form.is_valid():
            form.assign(profile)
            profile.save()
            logger.log(Action.ACTION_ACCOUNT, "Account updated info",
                       request.user)
            template_data['alert_success'] = "Your profile has been updated!"
    else:
        form = ProfileForm(profile.get_populated_fields())
    template_data['form'] = form
    return render(request, 'docnet/profile/update.html', template_data)
Пример #12
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 the template data from the 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
    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'].user,
                doctor=form.cleaned_data['doctor'].user,
                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)
            form = PrescriptionForm(
                default)  # Clean the form when the page is redisplayed
            form._errors = {}
            template_data[
                'alert_success'] = "Successfully added your prescription!"
    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, 'docnet/prescription/create.html', template_data)
Пример #13
0
def update_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(
        request, [Account.ACCOUNT_DOCTOR, Account.ACCOUNT_NURSE])
    if authentication_result is not None: return authentication_result
    # Validation Check. Make sure an appointment exists for the given pk.
    pk = request.GET['pk']
    try:
        medicalinfo = MedicalInfo.objects.get(pk=pk)
    except Exception:
        request.session[
            'alert_danger'] = "The requested medical info does not exist."
        return HttpResponseRedirect('/error/denied/')
    # Get the template data from the session
    template_data = views.parse_session(
        request, {
            'form_button': "Update Medical Info",
            'form_action': "?pk=" + pk,
            'medicalinfo': medicalinfo
        })
    # Proceed with the rest of the view
    request.POST._mutable = True
    request.POST['patient'] = medicalinfo.patient.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)
            template_data[
                'alert_success'] = "The medical info has been updated!"
            template_data['form'] = form
    else:
        form = MedicalInfoForm(medicalinfo.get_populated_fields())
        form.disable_field('patient')
    template_data['form'] = form
    return render(request, 'docnet/medicalinfo/update.html', template_data)
Пример #14
0
def new_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request)
    if authentication_result is not None: return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(request, {'form_button': "Send Message"})
    if request.method == 'POST':
        form = MessageForm(request.POST)
        if form.is_valid():
            message = Message(
                target=form.cleaned_data['target'],
                sender=request.user.account,
                header=form.cleaned_data['header'],
                body=form.cleaned_data['body'],
            )
            message.save()
            logger.log(Action.ACTION_MESSAGE, 'Message sent', request.user)
            form = MessageForm()  # Clean the form when the page is redisplayed
            template_data['alert_success'] = "Successfully sent your message!"
    else:
        form = MessageForm()
    template_data['form'] = form
    return render(request, 'docnet/message/new.html', template_data)
Пример #15
0
def read_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 an appointment exists for the given pk.
    pk = request.GET['pk']
    try:
        message = Message.objects.get(pk=pk)
    except Exception:
        request.session['alert_danger'] = "The requested message does not exist."
        return HttpResponseRedirect('/error/denied/')
    # Get the template data from the session
    if request.user.account == message.target and not message.read:
        message.read = True
        message.save()
        logger.log(Action.ACTION_MESSAGE, 'Message read', request.user)
    template_data = views.parse_session(request,
                                        {'to': message.target.profile,
                                         'from': message.sender.profile,
                                         'header': message.header,
                                         'body': message.body})
    # Proceed with the rest of the view
    return render(request, 'docnet/message/read.html', template_data)
Пример #16
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 = EmployeeRegisterForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                form.cleaned_data['email'].lower(
                ),  # Username, make sure it's lowercase
                form.cleaned_data['email'],  # Email
                form.cleaned_data['password_first']  # Password
            )
            profile = Profile(
                firstname=form.cleaned_data['firstname'],
                lastname=form.cleaned_data['lastname'],
            )
            profile.save()
            account = Account(role=form.cleaned_data['employee'],
                              profile=profile,
                              user=user)
            account.save()
            logger.log(Action.ACTION_ADMIN,
                       'Admin registered ' + user.username, request.user)
            form = EmployeeRegisterForm(
            )  # Clean the form when the page is redisplayed
            template_data[
                'alert_success'] = "Successfully created new employee account"
    else:
        form = EmployeeRegisterForm()
    template_data['form'] = form
    return render(request, 'docnet/admin/createemployee.html', template_data)
Пример #17
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)
            template_data[
                'alert_success'] = "Updated " + account.user.username + "'s role!"
    if 'search' in request.GET:
        template_data['query'] = Account.objects.filer(
            profile__firstname__icontains=request.GET['search'])
    else:
        template_data['query'] = Account.objects.all().order_by('-role')
    if 'sort' in request.GET:
        if request.GET['sort'] == 'username':
            template_data['query'] = Account.objects.all().order_by(
                'user__username')
        if request.GET['sort'] == 'firstname':
            template_data['query'] = Account.objects.all().order_by(
                'profile__firstname')
        if request.GET['sort'] == 'lastname':
            template_data['query'] = Account.objects.all().order_by(
                'profile__lastname')
    return render(request, 'docnet/admin/users.html', template_data)
Пример #18
0
def login_view(request):
    # Authentication check. Users currently logged in cannot view this page.
    if request.user.is_authenticated:
        return HttpResponseRedirect('/profile/')
    # Get the template data from the session
    template_data = parse_session(request, {'form_button': "Login"})
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = authenticate(
                username=form.cleaned_data['email'].lower(
                ),  # Make sure it's lowercase
                password=form.cleaned_data['password'])
            login(request, user)
            logger.log(Action.ACTION_ACCOUNT, "Account login", request.user)
            #logger.statlog("Account login")
            request.session[
                'alert_success'] = "Successfully logged into docnet."
            return HttpResponseRedirect('/profile/')
    else:
        form = LoginForm()
    template_data['form'] = form
    return render(request, 'docnet/login.html', template_data)