Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

actually volunteer dashboard #228

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions dashboard/templates/dashboard/dashboard-volunteer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{% extends "pttrack/base.html" %}

{% block title %}
Recent Clinic Dates
{% endblock %}

{% block header %}
<h1>Volunteer Dashboard<span class="label label-primary" style='vertical-align: text-top; font-size: 0.3em'>BETA</span></h1>
<small><a href="{% url 'old-home' %}">Take me back to the old home</a></small>
{% endblock %}

{% block content %}

<div class="container">

<h3>Active Patients without Notes</h3>
<table class="table table-striped">
<tr>
<th>Patient</th>
<th>First Seen</th>
</tr>
{% for patient in active_no_note_patients.all %}
<tr>
<td><a href="{% url 'patient-detail' pk=patient.id %}">{{ patient }}</a></td>
<td>{{ patient.history.last.history_date | date:"D d M Y" }}</td>
</tr>
{% endfor %}
<tr>
<td colspan="2" style="text-align:center;"><strong>&hellip;</strong></td>
</tr>
</table>

<h3>Active Patients with Notes</h3>
<table class="table table-striped">
<tr>
<th>Patient</th>
<th>First Seen</th>
</tr>
{% for patient in active_with_note_patients.all %}
<tr>
<td><a href="{% url 'patient-detail' pk=patient.id %}">{{ patient }}</a></td>
<td>{{ patient.history.last.history_date | date:"D d M Y" }}</td>
</tr>
{% endfor %}
<tr>
<td colspan="2" style="text-align:center;"><strong>&hellip;</strong></td>
</tr>
</table>

<h3>All the Patients You've Ever Seen Before</h3>
<table class="table table-striped">
<tr>
<th>Patient</th>
<th>First Seen</th>
</tr>
{% for patient in all_your_patients.all %}
<tr>
<td><a href="{% url 'patient-detail' pk=patient.id %}">{{ patient }}</a></td>
<td>{{ patient.history.last.history_date | date:"D d M Y" }}</td>
</tr>
{% endfor %}
<tr>
<td colspan="2" style="text-align:center;"><strong>&hellip;</strong></td>
</tr>
</table>

<nav aria-label="Page navigation" style='text-align: center;'>
<ul class="pagination">
<li {% if not clinics.has_previous %}class="disabled"{% endif %}>
<a {% if clinics.has_previous %} href="?page={{ clinics.previous_page_number }}" {% endif %} aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>

{% for i in clinics.paginator.page_range %}
<li {% if i == clinics.number %}class="active"{% endif %} ><a href="?page={{ i }}">{{ i }}</a></li>
{% endfor %}

<li {% if not clinics.has_next %}class="disabled"{% endif %}>
<a {% if clinics.has_next %} href="?page={{ clinics.next_page_number }}" {% endif %} aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
</ul>
</nav>
<div>
<p style='text-align:center'>Page {{ clinics.number }} of {{ clinics.paginator.num_pages }}</p>
</div>

</div>



{% endblock %}
153 changes: 153 additions & 0 deletions dashboard/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,159 @@ def test_root_redirect(self):
response = self.client.get(reverse('root'), follow=True)
self.assertTemplateUsed(response, 'pttrack/patient_list.html')

class TestVolunteerDashboard(TestCase):

fixtures = ['pttrack', 'workup']

def setUp(self):

self.clinical_student = build_provider(
roles=['Clinical'], email='user2@gmail.com')
log_in_provider(self.client, self.clinical_student)

self.preclinical_student = build_provider(
roles=["Preclinical"], email='user3@gmail.com')

self.wu_info = dict(
chief_complaint="SOB", diagnosis="MI", HPI="A", PMH_PSH="B",
meds="C", allergies="D", fam_hx="E", soc_hx="F", ros="", pe="",
A_and_P="")

self.clinic_today = ClinicDate.objects.create(
clinic_type=ClinicType.objects.first(),
clinic_date=now().date(),
gcal_id="tmp")

def test_pt_wo_note(self):
#active patient from clinic today without a note
response = self.client.get(reverse('dashboard-volunteer'))

self.pt2 = Patient.objects.create(
first_name="Arthur", last_name="Miller", middle_name="",
phone='+49 178 236 5288', gender=Gender.objects.first(),
address='Schulstrasse 9', city='Munich', state='BA',
zip_code='63108', pcp_preferred_zip='63018',
date_of_birth=datetime.date(1994, 01, 22),
patient_comfortable_with_english=False,
preferred_contact_method=ContactMethod.objects.first(),
)

self.assertEqual(
len(response.context['active_no_note_patients']),
1)
self.assertEqual(
response.context['active_no_note_patients'][0],
Patient.objects.first())
self.assertContains(response, reverse('patient-detail',
args=(self.pt2.pk,)))

def test_pt_w_note(self):
#active patient with note that you authored
response = self.client.get(reverse('dashboard-volunteer'))

pt3 = Patient.objects.create(
first_name="John", last_name="Doe", middle_name="",
phone='454545', gender=Gender.objects.first(),
address='A', city='B', state='C',
zip_code='12345', pcp_preferred_zip='12345',
date_of_birth=datetime.date(1992, 04, 22),
patient_comfortable_with_english=False,
preferred_contact_method=ContactMethod.objects.first(),
)
wu3 = Workup.objects.create(
clinic_day=self.clinic_today,
author=self.clinical_student,
author_type=self.clinical_student.clinical_roles.first(),
patient=pt3,
**self.wu_info)

self.assertEqual(
len(response.context['active_with_note_patients']),
1)
self.assertContains(response, reverse('patient-detail',
args=(self.pt3.pk,)))

#active patient with note that you saw (you are the other volunteer)
self.pt4 = Patient.objects.first()
self.wu4 = Workup.objects.create(
clinic_day=self.clinic_today,
author=self.preclinical_student,
other_volunteer=self.clinical_student,
author_type=self.preclinical_student.clinical_roles.first(),
patient=self.pt4,
**self.wu_info)

self.assertEqual(
len(response.context['active_with_note_patients']),
2)
self.assertContains(response, reverse('patient-detail',
args=(self.pt4.pk,)))

def test_old_pts_author(self):
#inactive/old pt that you saw previously and authored their note
response = self.client.get(reverse('dashboard-volunteer'))

self.pt5 = Patient.objects.create(
first_name="Minerva", last_name="Zhou", middle_name="",
phone='454545', gender=Gender.objects.first(),
address='A', city='B', state='C',
zip_code='12345', pcp_preferred_zip='12345',
date_of_birth=datetime.date(1995, 07, 21),
patient_comfortable_with_english=False,
preferred_contact_method=ContactMethod.objects.first(),
needs_workup=False,
)

self.old_clinic = ClinicDate.objects.create(
clinic_type=ClinicType.objects.first(),
clinic_date=now().date()-datetime.timedelta(days=1),
gcal_id="tmp")

self.wu5 = Workup.objects.create(
clinic_day=self.old_clinic,
author=self.clinical_student,
author_type=self.clinical_student.clinical_roles.first(),
patient=self.pt5,
**self.wu_info)

#this list will already have your active patients you've seen so length=3
self.assertEqual(
len(response.context['all_your_patients']),
3)
self.assertContains(response, reverse('patient-detail',
args=(self.pt3.pk,)))
self.assertContains(response, reverse('patient-detail',
args=(self.pt4.pk,)))
self.assertContains(response, reverse('patient-detail',
args=(self.pt5.pk,)))

#inactive/old pt that you saw previously and somebody else authored their note

self.pt6 = Patient.objects.create(
first_name="Vincent", last_name="Peng", middle_name="",
phone='454545', gender=Gender.objects.first(),
address='A', city='B', state='C',
zip_code='12345', pcp_preferred_zip='12345',
date_of_birth=datetime.date(1995, 07, 21),
patient_comfortable_with_english=False,
preferred_contact_method=ContactMethod.objects.first(),
needs_workup=False,
)

self.wu6 = Workup.objects.create(
clinic_day=self.old_clinic,
author=self.preclinical_student,
other_volunteer=self.clinical_student,
author_type=self.preclinical_student.clinical_roles.first(),
patient=self.pt6,
**self.wu_info)

self.assertEqual(
len(response.context['all_your_patients']),
4)
self.assertContains(response, reverse('patient-detail',
args=(self.pt6.pk,)))


class TestAttendingDashboard(TestCase):

Expand Down
3 changes: 3 additions & 0 deletions dashboard/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
url(r'^attending/$',
views.dashboard_attending,
name='dashboard-attending'),
url(r'^volunteer/$',
views.dashboard_volunteer,
name='dashboard-volunteer')
]

urlpatterns = [wrap_url(u, **{}) for u in unwrapped_urlconf]
33 changes: 32 additions & 1 deletion dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from django.shortcuts import render, redirect
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.conf import settings
from django.db.models import Q

from workup.models import ClinicDate
from workup.models import ClinicDate, Workup
from pttrack.models import Patient


Expand All @@ -23,6 +24,36 @@ def dashboard_dispatch(request):
else:
return redirect(settings.OSLER_DEFAULT_DASHBOARD)

def dashboard_volunteer(request):

provider = request.user.provider

clinic_list = ClinicDate.objects.filter(workup__attending=provider)

paginator = Paginator(clinic_list, settings.OSLER_CLINIC_DAYS_PER_PAGE,
allow_empty_first_page=True)

page = request.GET.get('page')
try:
clinics = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
clinics = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
clinics = paginator.page(paginator.num_pages)

active_no_note_patients = Patient.objects.filter(needs_workup=True, workup=None).order_by('-pk')[:20]
active_with_note_patients = Patient.objects.filter(~Q(workup=None) & Q(needs_workup=True) & Q(workup__in=Workup.objects.filter(Q(author=provider) | Q(other_volunteer=provider)).distinct())).order_by('-pk')[:20]
all_your_patients = Patient.objects.filter(workup__in=Workup.objects.filter(Q(author=provider) | Q(other_volunteer=provider)).distinct()).order_by('-pk')[:20]

return render(request,
'dashboard/dashboard-volunteer.html',
{'clinics': clinics,
'active_no_note_patients': active_no_note_patients,
'active_with_note_patients': active_with_note_patients,
'all_your_patients': all_your_patients
})

def dashboard_attending(request):

Expand Down
4 changes: 3 additions & 1 deletion osler/base_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,7 @@

OSLER_DEFAULT_DASHBOARD = 'home'
OSLER_PROVIDERTYPE_DASHBOARDS = {
'Attending': 'dashboard-attending'
'Attending': 'dashboard-attending',
'Clinical': 'dashboard-volunteer',
'Preclinical':'dashboard-volunteer',
}
2 changes: 1 addition & 1 deletion pttrack/templates/registration/logged_out.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h1>Success!</h1>
{% block content %}
<div class="container">
<h4>Thanks for spending some quality time with the Web site today.</strong></h4>
<a class="btn btn-default" href="{% url 'home' %}" role="button">Log in again</a>
<a class="btn btn-default" href="{% url 'dashboard-dispatch' %}" role="button">Log in again</a>

</div>
{% endblock %}
2 changes: 1 addition & 1 deletion pttrack/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
unwrapped_urlpatterns = [ # pylint: disable=invalid-name
url(r'^$',
views.home_page,
name="home"),
name="old-home"),
url(r'^all/$',
views.all_patients,
name="all-patients"),
Expand Down