Example #1
0
def parse_appointment_cancel(request, template_data):
    if request.method == 'POST':
        if 'cancel' in request.POST and 'pk' in request.POST:
            pk = request.POST['pk']
            try:
                appointment = Appointment.objects.get(pk=pk)
            except Exception:
                template_data['alert_danger'] = "Unable to cancel the appointment. Please try again later."
                return
            if request.user.account.role == Account.ACCOUNT_PATIENT and request.user.account != appointment.patient:
                template_data['alert_danger'] = "You don't have permission to cancel that appointment."
                return
            elif request.user.account.role == Account.ACCOUNT_DOCTOR and request.user.account != appointment.doctor:
                template_data['alert_danger'] = "You don't have permission to cancel that appointment."
                return
            elif appointment.status == "Cancelled":
                template_data['alert_danger'] = "That appointment was already cancelled."
                return
            appointment.status = "Cancelled"
            appointment.save()
            logger.log(Action.ACTION_APPOINTMENT, 'Appointment cancelled', request.user.account)
            if request.user.account.role == Account.ACCOUNT_DOCTOR:
                message.send_appointment_cancel(request, appointment, appointment.patient)
            if request.user.account.role == Account.ACCOUNT_PATIENT:
                message.send_appointment_cancel(request, appointment, appointment.doctor)
            template_data['alert_success'] = "The appointment has been cancelled."
Example #2
0
def setup_view(request):
    if Account.objects.all().count() > 0:
        request.session['alert_success'] = "Setup has already been completed."
        return HttpResponseRedirect('/')
    # 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 = 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 HealthNet's primary admin account."
            return HttpResponseRedirect('/profile/')
    else:
        form = AccountRegisterForm()
    template_data['form'] = form
    return render(request, 'healthnet/setup.html', template_data)
Example #3
0
def admit_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,
        {'form_button': "Admit"}
    )
    # Proceed with the rest of the view
    default = {}
    # Prefill some of the form values
    if 'hospital' not in request.POST and request.user.account.profile.prefHospital is not None:
        default['hospital'] = request.user.account.profile.prefHospital.pk
    if 'timestamp' not in request.POST:
        default['timestamp'] = datetime.now().strftime("%Y-%m-%d %H:%M")
    request.POST._mutable = True
    request.POST.update(default)
    form = AdmissionForm(request.POST)
    if request.method == 'POST':
        if form.is_valid():
            admission = form.generate()
            admission.save()
            logger.log(Action.ACTION_ADMISSION, 'Admitted Patient', request.user.account)
            form = AdmissionForm(default)  # Clean the form when the page is redisplayed
            form.clear_errors()
            request.session['alert_success'] = "Successfully admitted patient."  # Use session when passing data through a redirect
            return HttpResponseRedirect('/admission/list/')
    else:
        form._errors = {}
    template_data['form'] = form
    return render(request, 'healthnet/admission/admit.html', template_data)
Example #4
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 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 = PatientRegisterForm(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_PATIENT,
                form.cleaned_data['insurance']
            )
            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 registered with HealthNet."
            return HttpResponseRedirect('/profile/')
    else:
        form = PatientRegisterForm()
    template_data['form'] = form
    return render(request, 'healthnet/register.html', template_data)
Example #5
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.account)
                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, 'healthnet/profile/password.html', template_data)
Example #6
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 = views.register_user(
                form.cleaned_data['email'],
                form.cleaned_data['password_first'],
                form.cleaned_data['firstname'],
                form.cleaned_data['lastname'],
                form.cleaned_data['employee']
            )
            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 = EmployeeRegisterForm()
    template_data['form'] = form
    return render(request, 'healthnet/admin/createemployee.html', template_data)
Example #7
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"}
    )
    # 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 the person you're replying to. Please try again.."

        form = MessageForm(default)
        form.clear_errors()
    template_data['form'] = form
    return render(request, 'healthnet/message/new.html', template_data)
Example #8
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':
        if request.user.account.role != Account.ACCOUNT_PATIENT:
            form = EmployeeProfileForm(request.POST)
        else:
            form = ProfileForm(request.POST)
        if form.is_valid():
            form.assign(profile)
            profile.save()
            logger.log(Action.ACTION_ACCOUNT, "Account updated info", request.user.account)
            template_data['alert_success'] = "Your profile has been updated!"
    else:
        if request.user.account.role != Account.ACCOUNT_PATIENT:
            form = EmployeeProfileForm(profile.get_populated_fields())
        else:
            form = ProfileForm(profile.get_populated_fields())
    template_data['form'] = form
    return render(request, 'healthnet/profile/update.html', template_data)
Example #9
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 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 = PatientRegisterForm(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_PATIENT,
                                form.cleaned_data['insurance'])
            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 registered with HealthNet."
            return HttpResponseRedirect('/profile/')
    else:
        form = PatientRegisterForm()
    template_data['form'] = form
    return render(request, 'healthnet/register.html', template_data)
Example #10
0
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 the template data from the session
    template_data = views.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.account)
            request.session[
                'alert_success'] = "Successfully logged into HealthNet."
            return HttpResponseRedirect('/profile/')
    else:
        form = LoginForm()
    template_data['form'] = form
    return render(request, 'healthnet/login.html', template_data)
Example #11
0
def setup_view(request):
    if Account.objects.all().count() > 0:
        request.session['alert_success'] = "Setup has already been completed."
        return HttpResponseRedirect('/')
    # 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 = 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 HealthNet's primary admin account."
            return HttpResponseRedirect('/profile/')
    else:
        form = AccountRegisterForm()
    template_data['form'] = form
    return render(request, 'healthnet/setup.html', template_data)
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.method == 'POST':
        if 'delete' in request.POST and 'pk' in request.POST:
            pk = request.POST['pk']
            try:
                prescription = Prescription.objects.get(pk=pk)
                prescription.active = False
                prescription.save()
                logger.log(Action.ACTION_PRESCRIPTION, 'Prescription Cancelled', request.user.account)
                template_data['alert_success'] = "The prescription has been deleted."
            except Exception:
                template_data['alert_danger'] = "Unable to delete the prescription. Please try again later."
    if request.user.account.role == Account.ACCOUNT_DOCTOR:
        prescriptions = Prescription.objects.filter(doctor=request.user.account)
    elif request.user.account.role == Account.ACCOUNT_PATIENT:
        prescriptions = Prescription.objects.filter(patient=request.user.account)
    else:
        prescriptions = Prescription.objects.all()
    template_data['query'] = prescriptions.order_by('date')
    return render(request, 'healthnet/prescription/list.html', template_data)
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)
            if Appointment.objects.filter(
                    ~Q(pk=appointment.pk),
                    Q(status="Active"),
                    Q(doctor=appointment.doctor) | Q(patient=appointment.patient),
                    Q(startTime__range=(appointment.startTime, appointment.endTime)) | Q(endTime__range=(appointment.startTime, appointment.endTime))).count():
                form.mark_error('startTime', 'That time conflicts with another appointment.')
                form.mark_error('endTime', 'That time conflicts with another appointment.')
            else:
                appointment.save()
                logger.log(Action.ACTION_APPOINTMENT, 'Appointment updated', request.user.account)
                template_data['alert_success'] = "The appointment has been updated!"
                template_data['form'] = form
                if request.user.account.role == Account.ACCOUNT_PATIENT:
                    message.send_appointment_update(request, appointment, appointment.doctor)
                elif request.user.account.role == Account.ACCOUNT_DOCTOR:
                    message.send_appointment_update(request, appointment, appointment.patient)
                else:
                    message.send_appointment_update(request, appointment, appointment.doctor)
                    message.send_appointment_update(request, appointment, appointment.patient)

    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, 'healthnet/appointment/update.html', template_data)
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)
            if Appointment.objects.filter(
                    ~Q(pk=appointment.pk),
                    Q(status="Active"),
                    Q(doctor=appointment.doctor) | Q(patient=appointment.patient),
                    Q(startTime__range=(appointment.startTime, appointment.endTime)) | Q(endTime__range=(appointment.startTime, appointment.endTime))).count():
                form.mark_error('startTime', 'That time conflicts with another appointment.')
                form.mark_error('endTime', 'That time conflicts with another appointment.')
            else:
                appointment.save()
                logger.log(Action.ACTION_APPOINTMENT, 'Appointment updated', request.user.account)
                template_data['alert_success'] = "The appointment has been updated!"
                template_data['form'] = form
                if request.user.account.role == Account.ACCOUNT_PATIENT:
                    message.send_appointment_update(request, appointment, appointment.doctor)
                elif request.user.account.role == Account.ACCOUNT_DOCTOR:
                    message.send_appointment_update(request, appointment, appointment.patient)
                else:
                    message.send_appointment_update(request, appointment, appointment.doctor)
                    message.send_appointment_update(request, appointment, appointment.patient)

    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, 'healthnet/appointment/update.html', template_data)
Example #15
0
def send_message(sender, target, header, body):
    message = Message(
        target=target,
        sender=sender,
        header=header,
        body=body
    )
    message.save()
    logger.log(Action.ACTION_MESSAGE, 'Message sent', sender)
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
        if 'doctor' not in request.POST and request.user.account.profile.primaryCareDoctor is not None:
            default['doctor'] = request.user.account.profile.primaryCareDoctor.pk
    elif 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
    request.POST._mutable = True
    request.POST.update(default)
    form = AppointmentForm(request.POST)
    if request.method == 'POST':
        if form.is_valid():
            appointment = form.generate()
            if Appointment.objects.filter(
                    Q(status="Active"),
                    Q(doctor=appointment.doctor) | Q(patient=appointment.patient),
                    Q(startTime__range=(appointment.startTime, appointment.endTime)) | Q(endTime__range=(appointment.startTime, appointment.endTime))).count():
                form.mark_error('startTime', 'That time conflicts with another appointment.')
                form.mark_error('endTime', 'That time conflicts with another appointment.')
            else:
                appointment.save()
                logger.log(Action.ACTION_APPOINTMENT, 'Appointment created', request.user.account)
                form = AppointmentForm(default)  # Clean the form when the page is redisplayed
                form._errors = {}
                request.session['alert_success'] = "Successfully created your appointment!"
                if request.user.account.role == Account.ACCOUNT_PATIENT:
                    message.send_appointment_create(request, appointment, appointment.doctor)
                elif request.user.account.role == Account.ACCOUNT_DOCTOR:
                    message.send_appointment_create(request, appointment, appointment.patient)
                else:
                    message.send_appointment_create(request, appointment, appointment.doctor)
                    message.send_appointment_create(request, appointment, appointment.patient)
                return HttpResponseRedirect('/appointment/list/')
    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, 'healthnet/appointment/create.html', template_data)
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
        if 'doctor' not in request.POST and request.user.account.profile.primaryCareDoctor is not None:
            default['doctor'] = request.user.account.profile.primaryCareDoctor.pk
    elif 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
    request.POST._mutable = True
    request.POST.update(default)
    form = AppointmentForm(request.POST)
    if request.method == 'POST':
        if form.is_valid():
            appointment = form.generate()
            if Appointment.objects.filter(
                    Q(status="Active"),
                    Q(doctor=appointment.doctor) | Q(patient=appointment.patient),
                    Q(startTime__range=(appointment.startTime, appointment.endTime)) | Q(endTime__range=(appointment.startTime, appointment.endTime))).count():
                form.mark_error('startTime', 'That time conflicts with another appointment.')
                form.mark_error('endTime', 'That time conflicts with another appointment.')
            else:
                appointment.save()
                logger.log(Action.ACTION_APPOINTMENT, 'Appointment created', request.user.account)
                form = AppointmentForm(default)  # Clean the form when the page is redisplayed
                form._errors = {}
                request.session['alert_success'] = "Successfully created your appointment!"
                if request.user.account.role == Account.ACCOUNT_PATIENT:
                    message.send_appointment_create(request, appointment, appointment.doctor)
                elif request.user.account.role == Account.ACCOUNT_DOCTOR:
                    message.send_appointment_create(request, appointment, appointment.patient)
                else:
                    message.send_appointment_create(request, appointment, appointment.doctor)
                    message.send_appointment_create(request, appointment, appointment.patient)
                return HttpResponseRedirect('/appointment/list/')
    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, 'healthnet/appointment/create.html', template_data)
Example #18
0
def detail_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(
        request, [Account.ACCOUNT_PATIENT])
    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 and request.user.account.role != Account.ACCOUNT_NURSE:
            request.session[
                'alert_danger'] = "You don't have permission to view that 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 does not exist."
            return HttpResponseRedirect('/error/denied/')
    else:
        medicalinfo = MedicalInfo.objects.get(account=request.user.account)
    # Get the 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 the 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')
    form.disable_field('bloodType')
    form.disable_field('allergy')
    form.disable_field('alzheimer')
    form.disable_field('asthma')
    form.disable_field('diabetes')
    form.disable_field('stroke')
    form.disable_field('other')
    form.disable_field('comments')
    return render(request, 'healthnet/medicalinfo/view.html', template_data)
Example #19
0
def users_view_doctor(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.get('pk')
        pk2 = request.POST.get('pk2')
        role = request.POST.get('role')
        account = Account.objects.get(pk=pk)
        del_ = request.POST.get('del')
        limit = request.POST.get('limits')
        #import pdb; pdb.set_trace()
        if account is not None:
            if del_:
                pro = Profile.objects.get(pk=pk2)
                pro.hide = True
                pro.save()
                template_data[
                    'alert_danger'] = "Hidden " + account.user.username + "!!"
            elif limit:
                pro = Profile.objects.get(pk=pk2)
                pro.limit_users = limit
                pro.save()
                logger.log(
                    Action.ACTION_ADMIN, 'Admin modified ' +
                    account.user.username + "'s Patient limits",
                    request.user.account)
                template_data[
                    'alert_success'] = "Updated " + account.user.username + "'s Patient limits!"
            else:
                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!"
    # else:
    #     pk = request.GET['pk']
    #     account = Account.objects.get(pk=pk)
    #     account.delete()
    # Parse search sorting
    template_data['query'] = Account.objects.filter(role=30).filter(
        profile__hide=False)
    return render(request, 'healthnet/admin/users_doctor.html', template_data)
Example #20
0
def register_user(email, password, firstname, lastname, role, insurance=""):
    user = User.objects.create_user(email.lower(), email.lower(), password)
    profile = Profile(
        firstname=firstname,
        lastname=lastname,
        insurance=password,
    )
    profile.save()
    account = Account(role=role, profile=profile, user=user)
    account.save()
    medical_info = MedicalInfo(account=account)
    medical_info.save()
    logger.log(Action.ACTION_ACCOUNT, "Account registered", account)
    return user
Example #21
0
def logout_view(request):
    if request.user.is_authenticated():
        logger.log(Action.ACTION_ACCOUNT, "Account logout", request.user.account)
    # 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('/')
Example #22
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 HealthNet."
            return HttpResponseRedirect('/profile/')
    else:
        form = AccountRegisterForm()
    template_data['form'] = form
    return render(request, 'healthnet/register.html', template_data)
Example #23
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('/')
Example #24
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.all().order_by('-role')
    return render(request, 'healthnet/admin/users.html', template_data)
Example #25
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.all().order_by('-role')
    return render(request, 'healthnet/admin/users.html', template_data)
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
    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 the form when the 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, 'healthnet/prescription/create.html', template_data)
Example #27
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, 'healthnet/medtest/upload.html', template_data)
def update_view(request):
    # Authentication check.
    authentication_result = views.authentication_check(
        request,
        [Account.ACCOUNT_PATIENT, 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.
    if 'pk' in request.GET:
        if request.user.account.role != Account.ACCOUNT_DOCTOR and request.user.account.role != Account.ACCOUNT_NURSE:
            request.session['alert_danger'] = "You don't have permission to view that 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 does not exist."
            return HttpResponseRedirect('/error/denied/')
    else:
        medicalinfo = MedicalInfo.objects.get(account=request.user.account)
    # Get the 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 the 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, 'healthnet/medicalinfo/update.html', template_data)
Example #29
0
def hospital_update(request):
    # Authentication check.
    authentication_result = views.authentication_check(
        request,
        [Account.ACCOUNT_ADMIN]
    )
    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_ADMIN:
            request.session['alert_danger'] = "You don't have permission to view that page."
            return HttpResponseRedirect('/error/denied/')
        pk = request.GET['pk']
        try:
            hospital = Hospital.objects.get(pk=pk)
        except Exception:
            request.session['alert_danger'] = "The requested hospital does not exist."
            return HttpResponseRedirect('/error/denied/')
    else:
        hospital = Hospital.objects.all()
    # Get the template data from the session
    template_data = views.parse_session(
        request, {
            'form_button': "Update Hospital Info",
        })
    if 'pk' in request.GET:
        template_data['form_action'] = "?pk=" + pk
    # Proceed with the rest of the view
    request.POST._mutable = True
    request.POST['account'] = hospital.pk
    if request.method == 'POST':
        form = HospitalForm(request.POST)
        if form.is_valid():
            form.assign(hospital)
            medicalinfo.save()
            logger.log(Action.ACTION_MEDICALINFO, 'Hospital info updated', request.user.account)
            template_data['alert_success'] = "The Hospital info has been updated!"
    else:
        form = HospitalForm(hospital.get_populated_fields())
    template_data['form'] = form
    form.disable_field('name')
    return render(request, 'healthnet/admin/update_hospital.html', template_data)
Example #30
0
def admit_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,
        {'form_button': "Admit"}
    )
    # Proceed with the rest of the view
    default = {}
    # Prefill some of the form values
    if 'hospital' not in request.POST and request.user.account.profile.prefHospital is not None:
        default['hospital'] = request.user.account.profile.prefHospital.pk
    if 'timestamp' not in request.POST:
        default['timestamp'] = datetime.now().strftime("%Y-%m-%d %H:%M")
    request.POST._mutable = True
    request.POST.update(default)
    form = AdmitCreateForm(request.POST)
    # import pdb; pdb.set_trace()
    if request.method == 'POST' and request.user.account.profile.limit_users > 0:
        if form.is_valid():
            admission = form.jugaad()
            admission.doctor = request.user.account
            admission.save()
            dec = Profile.objects.get(pk=request.user.account.profile.pk)
            dec.limit_users -= 1
            dec.totat_patients += 1
            dec.save()
            logger.log(Action.ACTION_ADMISSION, 'Admitted Patient', request.user.account)
            form = AdmissionForm(default)  # Clean the form when the page is redisplayed
            form.clear_errors()
            request.session['alert_success'] = "Successfully admitted patient."  # Use session when passing data through a redirect
            return HttpResponseRedirect('/admission/list/')
    else:
        form._errors = {}
    template_data['form'] = form
    return render(request, 'healthnet/admission/admit.html', template_data)
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
    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 the form when the 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, 'healthnet/prescription/create.html', template_data)
Example #32
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, 'healthnet/profile/update.html', template_data)
Example #33
0
def register_admit_user(reason, email, firstname, lastname, hospital):
    password = ''.join(
        random.choice(string.ascii_uppercase + string.digits)
        for _ in range(8))
    insurance = password
    role = Account.ACCOUNT_PATIENT
    user = User.objects.create_user(email.lower(), email.lower(), password)
    profile = Profile(
        firstname=firstname,
        lastname=lastname,
        insurance=insurance,
    )
    profile.save()
    account = Account(role=role, profile=profile, user=user)
    account.save()
    medical_info = MedicalInfo(account=account)
    medical_info.save()
    admission = Admission(reason=reason, account=account, hospital=hospital)
    admission.save()
    logger.log(Action.ACTION_ACCOUNT, "Account registered", account)
    return admission
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, 'healthnet/appointment/create.html', template_data)
Example #35
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 a medical test exists for the 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 the template data from the session
    template_data = views.parse_session(
        request, {
            'form_button': "Update Medical Test",
            'form_action': "?pk=" + pk,
            'medtest': medicaltest
        })
    # Proceed with the rest of the view
    request.POST._mutable = True
    if request.user.account.role == Account.ACCOUNT_DOCTOR:
        request.POST['doctor'] = request.user.account.pk
    if request.method == 'POST':
        form = MedTestForm(request.POST)
        if form.is_valid():
            form.assign(medicaltest)
            medicaltest.save()
            logger.log(Action.ACTION_MEDTEST, 'Medical Test updated',
                       request.user.account)
            template_data[
                'alert_success'] = "The medical test has been updated!"
            template_data['form'] = form
    else:
        form = MedTestForm(medicaltest.get_populated_fields())
    if request.user.account.role == Account.ACCOUNT_DOCTOR:
        form.disable_field('doctor')
    template_data['form'] = form
    return render(request, 'healthnet/medtest/update.html', template_data)
Example #36
0
def parse_message_archive(request, template_data):
    if request.method == 'POST':
        if 'delete' in request.POST and 'pk' in request.POST:
            pk = request.POST['pk']
            try:
                message = Message.objects.get(pk=pk)
            except Exception:
                template_data['alert_danger'] = "Unable to archive the message. Please try again later."
                return
            if message.sender == request.user.account:
                if message.sender_deleted:
                    template_data['alert_danger'] = "That message was already archived."
                    return
                message.sender_deleted = True
            if message.target == request.user.account:
                if message.target_deleted:
                    template_data['alert_danger'] = "That message was already archived."
                    return
                message.target_deleted = True
            message.save()
            logger.log(Action.ACTION_MESSAGE, 'Message Archived', request.user.account)
            template_data['alert_success'] = "The message was archived."
Example #37
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, 'healthnet/medicalinfo/update.html', template_data)
Example #38
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, 'healthnet/message/new.html', template_data)
Example #39
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, 'healthnet/message/read.html', template_data)
Example #40
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, 'healthnet/admin/createemployee.html',
                  template_data)
Example #41
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 a medical test exists for the 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 the template data from the session
    template_data = views.parse_session(
        request,
        {
            'form_button': "Update Medical Test",
            'form_action': "?pk=" + pk,
            'medtest': medicaltest
        })
    # Proceed with the rest of the view
    request.POST._mutable = True
    if request.user.account.role == Account.ACCOUNT_DOCTOR:
        request.POST['doctor'] = request.user.account.pk
    if request.method == 'POST':
        form = MedTestForm(request.POST)
        if form.is_valid():
            form.assign(medicaltest)
            medicaltest.save()
            logger.log(Action.ACTION_MEDTEST, 'Medical Test updated', request.user.account)
            template_data['alert_success'] = "The medical test has been updated!"
            template_data['form'] = form
    else:
        form = MedTestForm(medicaltest.get_populated_fields())
    if request.user.account.role == Account.ACCOUNT_DOCTOR:
        form.disable_field('doctor')
    template_data['form'] = form
    return render(request, 'healthnet/medtest/update.html', template_data)
Example #42
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
    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 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, 'healthnet/medtest/upload.html', template_data)
Example #43
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.account)
                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, 'healthnet/profile/password.html', template_data)
Example #44
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
    if request.method == 'POST':
        if 'discharge' in request.POST and 'pk' in request.POST:
            pk = request.POST['pk']
            try:
                admission = Admission.objects.get(pk=pk)
                admission.active = False
                admission.discharged_timestamp = datetime.now()
                admission.save()
                logger.log(Action.ACTION_ADMISSION, 'Discharged Patient', request.user.account)
                template_data['alert_success'] = "The patient has been discharged."
            except Exception:
                template_data['alert_danger'] = "Unable to discharge the requested patient. Please try again later."
    template_data['query'] = Admission.objects.filter(doctor=request.user.account)
    return render(request, 'healthnet/admission/list.html', template_data)
Example #45
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
    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 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, 'healthnet/medtest/upload.html', template_data)
Example #46
0
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 the template data from the session
    template_data = views.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.account)
            request.session['alert_success'] = "Successfully logged into HealthNet."
            return HttpResponseRedirect('/profile/')
    else:
        form = LoginForm()
    template_data['form'] = form
    return render(request, 'healthnet/login.html', template_data)
Example #47
0
def register_user(email, password, firstname, lastname, role, insurance=""):
    user = User.objects.create_user(
        email.lower(),
        email.lower(),
        password
    )
    profile = Profile(
        firstname=firstname,
        lastname=lastname,
        insurance=insurance,
    )
    profile.save()
    account = Account(
        role=role,
        profile=profile,
        user=user
    )
    account.save()
    medical_info = MedicalInfo(
        account=account
    )
    medical_info.save()
    logger.log(Action.ACTION_ACCOUNT, "Account registered", account)
    return user
Example #48
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
    if request.method == 'POST':
        if 'discharge' in request.POST and 'pk' in request.POST:
            pk = request.POST['pk']
            try:
                admission = Admission.objects.get(pk=pk)
                admission.active = False
                admission.discharged_timestamp = datetime.now()
                admission.save()
                logger.log(Action.ACTION_ADMISSION, 'Discharged Patient', request.user.account)
                template_data['alert_success'] = "The patient has been discharged."
            except Exception:
                template_data['alert_danger'] = "Unable to discharge the requested patient. Please try again later."
    template_data['query'] = Admission.objects.all()
    return render(request, 'healthnet/admission/list.html', template_data)
Example #49
0
def send_message(sender, target, header, body):
    message = Message(target=target, sender=sender, header=header, body=body)
    message.save()
    logger.log(Action.ACTION_MESSAGE, 'Message sent', sender)