Skip to content

Commit

Permalink
Merge branch 'reorder-active-patients'
Browse files Browse the repository at this point in the history
  • Loading branch information
wwick committed Jan 3, 2021
2 parents 6c652c7 + 74bbf32 commit 704e5d9
Show file tree
Hide file tree
Showing 73 changed files with 1,381 additions and 1,175 deletions.
2 changes: 1 addition & 1 deletion compose/local/django/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN apt-get update \
# Requirements are installed here to ensure they will be cached.
COPY ./requirements /requirements
RUN pip install --upgrade pip
RUN pip install --use-feature=2020-resolver -r /requirements/local.txt
RUN pip install -r /requirements/local.txt

COPY ./compose/production/django/entrypoint /entrypoint
RUN sed -i 's/\r$//g' /entrypoint
Expand Down
9 changes: 7 additions & 2 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"rest_framework.authtoken",
'bootstrap3',
'simple_history',
'adminsortable',
]

LOCAL_APPS = [
Expand Down Expand Up @@ -225,7 +226,7 @@
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-httponly
SESSION_COOKIE_HTTPONLY = True
# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-httponly
CSRF_COOKIE_HTTPONLY = True
CSRF_COOKIE_HTTPONLY = False
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-browser-xss-filter
SECURE_BROWSER_XSS_FILTER = True
# https://docs.djangoproject.com/en/dev/ref/settings/#x-frame-options
Expand Down Expand Up @@ -375,4 +376,8 @@
OSLER_ATTENDANCE_URL = env(
"OSLER_ATTENDANCE_URL",
default="https://www.wustl.edu",
)
)

#Default Encounter Status
OSLER_DEFAULT_ACTIVE_STATUS = ('Active', True)
OSLER_DEFAULT_INACTIVE_STATUS = ('Inactive', False)
11 changes: 11 additions & 0 deletions osler.sublime-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"build_systems":
[
],
"folders":
[
{
"path": "."
}
]
}
4 changes: 0 additions & 4 deletions osler/appointment/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ def get_initial(self):

date = self.request.GET.get('date', None)
if date is not None:
# If appointment attribute clindate = workup.models.ClinicDate,
# default date could be next clindate.
# For now, the default value will be the next Saturday
# (including day of)
initial['clindate'] = date

return initial
11 changes: 10 additions & 1 deletion osler/core/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib import admin
from adminsortable.admin import SortableAdmin

from osler.utils import admin as admin_utils
from osler.core import models
Expand All @@ -7,8 +8,16 @@
for model in [models.Language, models.Patient,
models.Gender, models.ActionInstruction, models.Ethnicity,
models.ReferralType, models.ReferralLocation,
models.ContactMethod, models.DocumentType, models.Outcome]:
models.ContactMethod, models.DocumentType, models.Outcome, models.EncounterStatus]:
admin_utils.simplehistory_aware_register(model)

admin.site.register(models.Document, admin_utils.NoteAdmin)
admin.site.register(models.ActionItem, admin_utils.ActionItemAdmin)


@admin.register(models.Encounter)
class EncounterAdmin(SortableAdmin):
list_display = ('__str__', 'status')
list_filter = ('clinic_day','status')
#made a custom so I could javascript fix the url idk why
sortable_change_list_template = 'adminsortable/custom_change_list.html'
2 changes: 1 addition & 1 deletion osler/core/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Meta(object):
age = serializers.StringRelatedField(read_only=True)
name = serializers.StringRelatedField(read_only=True)
pk = serializers.StringRelatedField(read_only=True)
status = serializers.StringRelatedField(read_only=True)
actionitem_status = serializers.StringRelatedField(read_only=True)
case_managers = CaseManagerSerializer(many=True)

# Put urls as model properties because unable to do:
Expand Down
37 changes: 19 additions & 18 deletions osler/core/api/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,7 @@ class APITest(APITestCase):
fixtures = [BASIC_FIXTURE]

def setUp(self):
workupModels.ClinicType.objects.create(name="Basic Care Clinic")
workupModels.ClinicDate.objects.create(
clinic_type=workupModels.ClinicType.objects.first(),
clinic_date=now().date() + datetime.timedelta(days=1))
workupModels.ClinicDate.objects.create(
clinic_type=workupModels.ClinicType.objects.first(),
clinic_date=now().date() - datetime.timedelta(days=1))
workupModels.ClinicDate.objects.create(
clinic_type=workupModels.ClinicType.objects.first(),
clinic_date=now().date() - datetime.timedelta(days=5))
models.EncounterStatus.objects.create(name="Active",is_active=True)
log_in_provider(self.client, build_provider(["Attending"]))

pt1 = models.Patient.objects.get(pk=1)
Expand Down Expand Up @@ -83,8 +74,12 @@ def setUp(self):
)

# Give pt2 a workup one day later.
e1 = models.Encounter.objects.create(
patient=pt2,
clinic_day=now().date() + datetime.timedelta(days=1),
status=models.EncounterStatus.objects.first())
workupModels.Workup.objects.create(
clinic_day=workupModels.ClinicDate.objects.first(), # one day later
encounter=e1, # one day later
chief_complaint="SOB",
diagnosis="MI",
hpi="", pmh="", psh="", meds="", allergies="", fam_hx="", soc_hx="",
Expand All @@ -94,8 +89,12 @@ def setUp(self):
patient=pt2)

# Give pt3 a workup one day ago.
e2 = models.Encounter.objects.create(
patient=pt3,
clinic_day=now().date() - datetime.timedelta(days=1),
status=models.EncounterStatus.objects.first())
workupModels.Workup.objects.create(
clinic_day=workupModels.ClinicDate.objects.all()[1], # one day ago
encounter=e2, # one day ago
chief_complaint="SOB",
diagnosis="MI",
hpi="", pmh="", psh="", meds="", allergies="", fam_hx="", soc_hx="",
Expand All @@ -106,8 +105,12 @@ def setUp(self):


# Give pt1 a signed workup five days ago.
e3 = models.Encounter.objects.create(
patient=pt1,
clinic_day=now().date() - datetime.timedelta(days=5),
status=models.EncounterStatus.objects.first())
workupModels.Workup.objects.create(
clinic_day=workupModels.ClinicDate.objects.all()[2], # five days ago
encounter=e3, # five days ago
chief_complaint="SOB",
diagnosis="MI",
hpi="", pmh="", psh="", meds="", allergies="", fam_hx="", soc_hx="",
Expand Down Expand Up @@ -187,8 +190,8 @@ def test_api_list_patients_with_unsigned_workup(self):
self.assertEqual(response.data[1]['id'], pt3.id)
self.assertLessEqual(response.data[0]['last_name'],response.data[1]['last_name']) # check that sorting is correct

def test_api_list_active_patients(self):
# Test displaying active patients (needs_workup is true).
def donttest_api_list_active_patients(self):
# Test displaying active patients
data = {'filter':'active'}
response = self.client.get(reverse("pt_list_api"), data, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
Expand All @@ -197,9 +200,7 @@ def test_api_list_active_patients(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertGreaterEqual(len(response.data), 1)
for patient in response.data:
self.assertEqual(patient['needs_workup'], True)
# self.assertEqual(response.data[0]['needs_workup'], True)
# self.assertEqual(response.data[1]['needs_workup'], True)
self.assertEqual(patient['get_status.is_active'], True)
self.assertLessEqual(response.data[0]['last_name'],response.data[1]['last_name']) # check that sorting is correct

def test_api_list_patients_with_priority_action_item(self):
Expand Down
4 changes: 2 additions & 2 deletions osler/core/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def active_patients_filter(qs):
pts).
'''

return qs.filter(needs_workup__exact=True).order_by('last_name')
return qs.filter(encounter__status__is_active=True).order_by('last_name')


def merge_pt_querysets_by_soonest_date(qs1, qs2):
Expand Down Expand Up @@ -170,7 +170,7 @@ def bylatestKey(pt):
if latestwu is None:
latestdate = pt.history.last().history_date.date()
else:
latestdate = latestwu.clinic_day.clinic_date
latestdate = latestwu.encounter.clinic_day
return latestdate

queryset = core_models.Patient.objects
Expand Down
3 changes: 2 additions & 1 deletion osler/core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, *args, **kwargs):
class PatientForm(ModelForm):
class Meta(object):
model = models.Patient
exclude = ['needs_workup', 'demographics']
exclude = ['demographics']
if not settings.OSLER_DISPLAY_CASE_MANAGERS:
exclude.append('case_managers')

Expand Down Expand Up @@ -165,3 +165,4 @@ def __init__(self, *args, **kwargs):
super(DocumentForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.add_input(Submit('submit', 'Submit'))

43 changes: 43 additions & 0 deletions osler/core/migrations/0006_encounter_encounterstatus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 3.1.2 on 2020-12-04 00:38

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('workup', '0006_auto_20201114_1735'),
('core', '0005_auto_20201114_1258'),
]

operations = [
migrations.CreateModel(
name='EncounterStatus',
fields=[
('name', models.CharField(max_length=100, primary_key=True, serialize=False)),
('is_active', models.BooleanField(default=False)),
],
),
migrations.CreateModel(
name='Encounter',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('order', models.PositiveIntegerField(db_index=True, default=0, editable=False)),
('patient', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='core.patient')),
('status', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='core.encounterstatus')),
('clinic_day', models.DateField()),
],
options={
'ordering': ['order'],
},
),
migrations.RemoveField(
model_name='historicalpatient',
name='needs_workup',
),
migrations.RemoveField(
model_name='patient',
name='needs_workup',
),
]
55 changes: 55 additions & 0 deletions osler/core/migrations/0007_make_encounters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Generated by Django 3.1.2 on 2020-12-07 17:40

from django.db import migrations
from django.conf import settings

def make_encounter(apps, schema_editor):
Encounter = apps.get_model('core','Encounter')
EncounterStatus = apps.get_model('core','EncounterStatus')

default_inactive = EncounterStatus.objects.get_or_create(
name=settings.OSLER_DEFAULT_INACTIVE_STATUS[0],
is_active=settings.OSLER_DEFAULT_INACTIVE_STATUS[1])[0]

Workup = apps.get_model('workup','Workup')
for workup in Workup.objects.all():
workup.encounter = Encounter.objects.get_or_create(
patient=workup.patient,
clinic_day=workup.clinic_day.clinic_date,
status=default_inactive)[0]
workup.save()

Lab = apps.get_model('labs','Lab')
for lab in Lab.objects.all():
lab.encounter = Encounter.objects.get_or_create(
patient=lab.patient,
clinic_day=lab.lab_time,
status=default_inactive)[0]
lab.save()

note_types = [('workup','BasicNote'), ('workup','AttestableBasicNote'),
('inventory','DispenseHistory'),('vaccine','VaccineDose')]

for app, model in note_types:
notes = apps.get_model(app, model)
for note in notes.objects.all():
note.encounter = Encounter.objects.get_or_create(
patient=note.patient,
clinic_day=note.written_datetime,
status=default_inactive)[0]
note.save()


class Migration(migrations.Migration):

dependencies = [
('core', '0006_encounter_encounterstatus'),
('workup', '0007_auto_20201203_1940'),
('labs','0003_lab_encounter'),
('inventory','0003_dispensehistory_encounter'),
('vaccine','0002_vaccinedose_encounter')
]

operations = [
migrations.RunPython(make_encounter),
]
Loading

0 comments on commit 704e5d9

Please sign in to comment.