fix collection ordering
This commit is contained in:
+13
-2
@@ -816,13 +816,17 @@ class CaseCollection(ExamOrCollectionGenericBase):
|
|||||||
|
|
||||||
# return False
|
# return False
|
||||||
|
|
||||||
|
def get_cases(self):
|
||||||
|
"""Returns the cases in the collection in order of the CaseDetail sort_order"""
|
||||||
|
return self.cases.all().order_by("casedetail__sort_order")
|
||||||
|
|
||||||
def get_case_by_index(
|
def get_case_by_index(
|
||||||
self, case_index: int, case_count=False
|
self, case_index: int, case_count=False
|
||||||
) -> Case | Tuple[Case, int]:
|
) -> Case | Tuple[Case, int]:
|
||||||
# Seems to be a bug when case_number is 0 or 1 the same (first) object gets returned
|
# Seems to be a bug when case_number is 0 or 1 the same (first) object gets returned
|
||||||
# forces a list fixes (but is likely inefficient)
|
# forces a list fixes (but is likely inefficient)
|
||||||
cases = list(
|
cases = list(
|
||||||
self.cases.all().order_by("casedetail__sort_order").prefetch_related()
|
self.get_cases().prefetch_related()
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -838,7 +842,7 @@ class CaseCollection(ExamOrCollectionGenericBase):
|
|||||||
|
|
||||||
def get_case_take_url(self, case):
|
def get_case_take_url(self, case):
|
||||||
cases = list(
|
cases = list(
|
||||||
self.cases.all().order_by("casedetail__sort_order").prefetch_related()
|
self.get_cases().prefetch_related()
|
||||||
)
|
)
|
||||||
|
|
||||||
return reverse(
|
return reverse(
|
||||||
@@ -878,6 +882,13 @@ class CaseCollection(ExamOrCollectionGenericBase):
|
|||||||
"studies": studies
|
"studies": studies
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def add_case(self, case):
|
||||||
|
"""Adds a case to the collection and makes sure order is maintained"""
|
||||||
|
# We might be better off adding via the case detail model direct
|
||||||
|
#CaseDetail.objects.create(case=case, collection=self)
|
||||||
|
self.cases.add(case)
|
||||||
|
self.order_cases()
|
||||||
|
|
||||||
|
|
||||||
def order_cases(self):
|
def order_cases(self):
|
||||||
"""Modifies the casedetail sort_order to sequentially order the cases"""
|
"""Modifies the casedetail sort_order to sequentially order the cases"""
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<h3>Cases</h3>
|
<h3>Cases</h3>
|
||||||
<ol id="full-question-list" class="sortable">
|
<ol id="full-question-list" class="sortable">
|
||||||
{% for casedetail in casesdetails %}
|
{% for casedetail in casesdetails %}
|
||||||
<li data-question_pk={{case.pk}}><a title="sort_order: {{casedetail.sort_order}}" href="{% url 'atlas:collection_case_view' pk=collection.pk case_number=forloop.counter0 %}">Case {{forloop.counter}}</a>
|
<li data-question_pk={{casedetail.case.pk}}><a title="sort_order: {{casedetail.sort_order}}" href="{% url 'atlas:collection_case_view' pk=collection.pk case_number=forloop.counter0 %}">Case {{forloop.counter}}</a>
|
||||||
: {{casedetail.case.title}}
|
: {{casedetail.case.title}}
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
|||||||
+45
-3
@@ -107,10 +107,52 @@ def create_case(
|
|||||||
case.presentation.add(presentation)
|
case.presentation.add(presentation)
|
||||||
case.pathological_process.add(pathological_process)
|
case.pathological_process.add(pathological_process)
|
||||||
case.author.add(user)
|
case.author.add(user)
|
||||||
case.editor.add(user)
|
|
||||||
|
|
||||||
return case
|
return case
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def make_case(create_subspecialty, create_condition, create_presentation, create_pathological_process):
|
||||||
|
def _make_case(
|
||||||
|
title="Sample Case",
|
||||||
|
description="Sample description",
|
||||||
|
history="Sample history",
|
||||||
|
discussion="Sample discussion",
|
||||||
|
report="Sample report",
|
||||||
|
diagnostic_certainty=Case.CertaintyChoices.LIKELY,
|
||||||
|
verified=True,
|
||||||
|
created_date=timezone.now(),
|
||||||
|
published_date=timezone.now(),
|
||||||
|
archive=False,
|
||||||
|
open_access=True,
|
||||||
|
):
|
||||||
|
subspecialty = create_subspecialty
|
||||||
|
condition = create_condition
|
||||||
|
presentation = create_presentation
|
||||||
|
pathological_process = create_pathological_process
|
||||||
|
user, _ = get_user_model().objects.get_or_create(
|
||||||
|
username="Test User 2", password="Test Password", email="test@emai.com")
|
||||||
|
|
||||||
|
case = Case.objects.create(
|
||||||
|
title=title,
|
||||||
|
description=description,
|
||||||
|
history=history,
|
||||||
|
discussion=discussion,
|
||||||
|
report=report,
|
||||||
|
diagnostic_certainty=diagnostic_certainty,
|
||||||
|
verified=verified,
|
||||||
|
created_date=created_date,
|
||||||
|
published_date=published_date,
|
||||||
|
archive=archive,
|
||||||
|
open_access=open_access,
|
||||||
|
)
|
||||||
|
case.subspecialty.add(subspecialty)
|
||||||
|
case.condition.add(condition)
|
||||||
|
case.presentation.add(presentation)
|
||||||
|
case.pathological_process.add(pathological_process)
|
||||||
|
case.author.add(user)
|
||||||
|
|
||||||
|
return case
|
||||||
|
return _make_case
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def create_series(create_modality, create_examination, create_plane, create_contrast, create_user):
|
def create_series(create_modality, create_examination, create_plane, create_contrast, create_user):
|
||||||
@@ -141,12 +183,12 @@ def create_series_image():
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def create_series_finding():
|
def create_series_finding():
|
||||||
return SeriesFinding.objects.create()
|
return SeriesFinding.objects.create(description="Test Description")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def create_case_collection():
|
def create_case_collection():
|
||||||
return CaseCollection.objects.create()
|
return CaseCollection.objects.create(name="Test Collection")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
import pytest
|
import pytest
|
||||||
from atlas.models import Finding, Condition
|
from atlas.models import CaseCollection, Finding, Condition
|
||||||
#from atlas.views import GenericExamViews
|
#from atlas.views import GenericExamViews
|
||||||
|
|
||||||
#@pytest.mark.django_db
|
#@pytest.mark.django_db
|
||||||
@@ -81,3 +81,48 @@ def test_create_case(db, create_case):
|
|||||||
def test_create_series(db, create_series):
|
def test_create_series(db, create_series):
|
||||||
series = create_series
|
series = create_series
|
||||||
assert series
|
assert series
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_collection(db, create_case_collection, create_case, make_case, client):
|
||||||
|
collection: CaseCollection = create_case_collection
|
||||||
|
|
||||||
|
# create some cases
|
||||||
|
case1 = create_case
|
||||||
|
case2 = make_case()
|
||||||
|
case3 = make_case(title="Case 3")
|
||||||
|
case4 = make_case(title="Case 4")
|
||||||
|
|
||||||
|
collection.cases.set([case1, case2, case3, case4])
|
||||||
|
|
||||||
|
case5 = make_case(title="Case 5")
|
||||||
|
|
||||||
|
assert collection.cases.all().count() == 4
|
||||||
|
|
||||||
|
collection.add_case(case5)
|
||||||
|
|
||||||
|
assert collection.cases.all().count() == 5
|
||||||
|
|
||||||
|
assert collection.get_case_by_index(0) == case1
|
||||||
|
assert collection.get_case_by_index(1) == case2
|
||||||
|
assert collection.get_case_by_index(2) == case3
|
||||||
|
assert collection.get_case_by_index(3) == case4
|
||||||
|
assert collection.get_case_by_index(4) == case5
|
||||||
|
|
||||||
|
assert collection.get_absolute_url() == reverse("atlas:collection_detail", kwargs={"pk": collection.pk})
|
||||||
|
|
||||||
|
assert collection.get_take_url() == reverse("atlas:collection_take_start", kwargs={"pk": collection.pk})
|
||||||
|
|
||||||
|
new_order = [
|
||||||
|
case5.pk,
|
||||||
|
case1.pk,
|
||||||
|
case2.pk,
|
||||||
|
case3.pk,
|
||||||
|
case4.pk
|
||||||
|
]
|
||||||
|
response = client.post(reverse("atlas:exam_json_edit", kwargs={"pk":collection.pk} ), json=new_order, follow=True)
|
||||||
|
# Check that sorting the exam works
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.content == b"OK"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -391,8 +391,7 @@ def add_case_to_collection(request, collection_id):
|
|||||||
if case in collection.cases.all():
|
if case in collection.cases.all():
|
||||||
return HttpResponse("Case already in collection")
|
return HttpResponse("Case already in collection")
|
||||||
print(case)
|
print(case)
|
||||||
collection.cases.add(case)
|
collection.add_case(case)
|
||||||
collection.order_cases()
|
|
||||||
return HttpResponse("Case added to collection")
|
return HttpResponse("Case added to collection")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user