コード例 #1
0
def list_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)
    # Proceed with the rest of the view
    if request.user.account.role == Account.ACCOUNT_PATIENT:
        appointments = Appointment.objects.filter(patient=request.user)
    elif request.user.account.role == Account.ACCOUNT_DOCTOR:
        appointments = Appointment.objects.filter(doctor=request.user)
    else:
        appointments = Appointment.objects.all()
    # Page sorting.
    template_data['query'] = appointments.order_by('date', 'startTime')
    if 'sort' in request.GET:
        if request.GET['sort'] == 'doctor':
            template_data['query'] = appointments.order_by(
                'doctor__username', 'date', 'startTime')
        if request.GET['sort'] == 'patient':
            template_data['query'] = appointments.order_by(
                'patient__username', 'date', 'startTime')
        if request.GET['sort'] == 'description':
            template_data['query'] = appointments.order_by(
                'description', 'date', 'startTime')
        if request.GET['sort'] == 'hospital':
            template_data['query'] = appointments.order_by(
                'hospital__name', 'date', 'startTime')
        if request.GET['sort'] == 'status':
            template_data['query'] = appointments.order_by(
                'active', 'date', 'startTime')
    return render(request, 'docnet/appointment/list.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 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)
コード例 #5
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 the given pk.
    pk = request.GET['pk']
    try:
        medtest = MedicalTest.objects.get(pk=pk)
    except Exception:
        request.session[
            'alert_danger'] = "The requested medical test does not exist"
        return HttpResponseRedirect('/error/denied/')
    template_data = views.parse_session(
        request, {
            'form_button': "Return to list of Medical Tests",
            'form_action': "?pk=" + pk,
            'medtest': medtest
        })
    if request.method == 'GET':
        form = MedTestForm(medtest.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
    else:
        return HttpResponseRedirect('/medtest/list')
    return render(request, 'docnet/medtest/display.html', template_data)
コード例 #6
0
def list_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request, [
        Account.ACCOUNT_DOCTOR, Account.ACCOUNT_NURSE, Account.ACCOUNT_PATIENT
    ])
    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.user.account.role == Account.ACCOUNT_DOCTOR:
        medtests = MedicalTest.objects.all()
    elif request.user.account.role == Account.ACCOUNT_NURSE:
        medtests = MedicalTest.objects.filter(
            hospital=request.user.account.profile.prefHospital)
    else:
        medtests = MedicalTest.objects.filter(patient=request.user,
                                              private=False)
    # Page sorting
    template_data['query'] = medtests.order_by('date')
    if 'sort' in request.GET:
        if request.GET['sort'] == 'doctor':
            template_data['query'] = medtests.order_by('doctor__username',
                                                       'date')
        if request.GET['sort'] == 'patient':
            template_data['query'] = medtests.order_by('patient__username',
                                                       'date')
        if request.GET['sort'] == 'description':
            template_data['query'] = medtests.order_by('description', 'date')
        if request.GET['sort'] == 'hospital':
            template_data['query'] = medtests.order_by('hospital__name',
                                                       'date')
        if request.GET['sort'] == 'name':
            template_data['query'] == medtests.order_by('name', 'date')
    return render(request, 'docnet/medtest/list.html', template_data)
コード例 #7
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)
コード例 #8
0
ファイル: views_admin.py プロジェクト: lelouche556/docnet2.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, {'query': Action.objects.all().order_by('-timePerformed')})
    # Proceed with the rest of the view
    if 'sort' in request.GET:
        if request.GET['sort'] == 'description':
            template_data['query'] = Action.objects.all().order_by(
                'description', '-timePerformed')
        if request.GET['sort'] == 'user':
            template_data['query'] = Action.objects.all().order_by(
                'user__username', '-timePerformed')
        if request.GET['sort'] == 'type':
            template_data['query'] = Action.objects.all().order_by(
                'type', 'description', '-timePerformed')
    return render(request, 'docnet/admin/stats.html', template_data)

    #template_data = views.parse_session(request, {'query': Statistics.objects.all().order_by('freq')})
    # Proceed with the rest of the view

# if 'sort' in request.GET:
# if request.GET['sort' == 'statistic':
#   template_data['query'] = Statistics.objects.all().order_by('statistics','freq')
コード例 #9
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)
コード例 #10
0
def profile_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)
    # Proceed with the rest of the view
    return render(request, 'docnet/profile.html', template_data)
コード例 #11
0
def patient_view(request):
    authentication_result = views.authentication_check(
        request, [Account.ACCOUNT_PATIENT])
    if authentication_result is not None: return authentication_result
    default = {}
    template_data = views.parse_session(request)
    if request.user.account.role == Account.ACCOUNT_PATIENT:
        default['patient'] = request.user.account.pk
    else:
        request.session[
            'alert_danger'] = "The requested medical info does not exist."
        return HttpResponseRedirect('/error/denied/')
    request.POST._mutable = True
    request.POST.update(default)
    form = MedicalInfoForm(request.POST)
    form.disable_field('patient')
    template_data['form'] = form
    return render(request, 'docnet/medicalinfo/patient.html', template_data)
コード例 #12
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)
コード例 #13
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)
コード例 #14
0
def list_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(
        request, [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)
    # Proceed with the rest of the view
    medicalinfoes = MedicalInfo.objects.all()
    # Page sorting.
    template_data['query'] = medicalinfoes.order_by('patient')
    if 'sort' in request.GET:
        if request.GET['sort'] == 'patient':
            template_data['query'] = medicalinfoes.order_by('patient')
        if request.GET['sort'] == 'bloodType':
            template_data['query'] = medicalinfoes.order_by('bloodType')
        if request.GET['sort'] == 'allergy':
            template_data['query'] = medicalinfoes.order_by('allergy')
    return render(request, 'docnet/medicalinfo/list.html', template_data)
コード例 #15
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)
コード例 #16
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)
コード例 #17
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)
コード例 #18
0
def list_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)
    # Proceed with the rest of the view
    messages = Message.objects.filter(Q(sender=request.user.account) | Q(target=request.user.account))
    # Page sorting.
    template_data['query'] = messages.order_by('timestamp')
    if 'sort' in request.GET:
        if request.GET['sort'] == 'to':
            template_data['query'] = messages.order_by('target__profile', 'timestamp')
        if request.GET['sort'] == 'from':
            template_data['query'] = messages.order_by('sender__profile', 'timestamp')
        if request.GET['sort'] == 'subject':
            template_data['query'] = messages.order_by('header', 'timestamp')
        if request.GET['sort'] == 'time':
            template_data['query'] = messages.order_by('timestamp')
        if request.GET['sort'] == 'read':
            template_data['query'] = messages.order_by('read', 'timestamp')
    return render(request, 'docnet/message/list.html', template_data)
コード例 #19
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)
コード例 #20
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)
コード例 #21
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)
コード例 #22
0
ファイル: views_admin.py プロジェクト: lelouche556/docnet2.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)
コード例 #23
0
ファイル: views_admin.py プロジェクト: lelouche556/docnet2.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)
コード例 #24
0
def list_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(request, [
        Account.ACCOUNT_DOCTOR, Account.ACCOUNT_NURSE, Account.ACCOUNT_PATIENT
    ])
    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.user.account.role == Account.ACCOUNT_DOCTOR:
        prescriptions = Prescription.objects.filter(doctor=request.user)
    elif request.user.account.role == Account.ACCOUNT_PATIENT:
        prescriptions = Prescription.objects.filter(patient=request.user)
    else:
        prescriptions = Prescription.objects.all()
    template_data['query'] = prescriptions.order_by('date')
    if 'sort' in request.GET:
        if request.GET['sort'] == 'doctor':
            template_data['query'] = prescriptions.order_by(
                'doctor__username', 'date')
        elif request.GET['sort'] == 'patient':
            template_data['query'] = prescriptions.order_by(
                'patient__username', 'date')
        elif request.GET['sort'] == 'medi cation':
            template_data['query'] = prescriptions.order_by(
                'medication', 'date')
        elif request.GET['sort'] == 'strength':
            template_data['query'] = prescriptions.order_by('strength', 'date')
        elif request.GET['sort'] == 'refill':
            template_data['query'] = prescriptions.order_by('refill', 'date')
        elif request.GET['sort'] == 'status':
            template_data['query'] = prescriptions.order_by(
                'active',
                'date',
            )
    return render(request, 'docnet/prescription/list.html', template_data)
コード例 #25
0
def list_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)
    # Proceed with the rest of the view

    admissions = Admission.objects.all()
    # Page sorting.
    template_data['query'] = admissions.order_by('date', 'time')
    if 'sort' in request.GET:
        if request.GET['sort'] == 'patient':
            template_data['query'] = admissions.order_by(
                'patient__username', 'date', 'time')
        if request.GET['sort'] == 'reason':
            template_data['query'] = admissions.order_by(
                'reason', 'date', 'time')
        if request.GET['sort'] == 'hospital':
            template_data['query'] = admissions.order_by(
                'hospital__name', 'date', 'time')
    return render(request, 'docnet/admission/list.html', template_data)