diff --git a/anatomy/templates/anatomy/exam_overview.html b/anatomy/templates/anatomy/exam_overview.html index 9dc31beb..8f088cd6 100644 --- a/anatomy/templates/anatomy/exam_overview.html +++ b/anatomy/templates/anatomy/exam_overview.html @@ -89,10 +89,12 @@ }) $("#button-open-access").click(function () { $.ajax({ - url: "{% url 'anatomy:exam_json_edit' pk=exam.pk %}", + url: "{% url 'generic:generic_exam_json_edit' %}", data: { csrfmiddlewaretoken: "{{ csrf_token }}", set_open_access: true, + type: "anatomy", + exam_id: "{{exam.pk}}", }, type: "POST", dataType: "json", @@ -111,10 +113,13 @@ }) $("#button-closed-access").click(function () { $.ajax({ - url: "{% url 'anatomy:exam_json_edit' pk=exam.pk %}", + //url: "{% url 'anatomy:exam_json_edit' pk=exam.pk %}", + url: "{% url 'generic:generic_exam_json_edit' %}", data: { csrfmiddlewaretoken: "{{ csrf_token }}", set_open_access: false, + type: "anatomy", + exam_id: "{{exam.pk}}", }, type: "POST", dataType: "json", diff --git a/generic/urls.py b/generic/urls.py index a5d7ee67..75cc2b83 100755 --- a/generic/urls.py +++ b/generic/urls.py @@ -11,4 +11,7 @@ urlpatterns = [ path("examination/ajax/get_examination_id", views.get_examination_id, name="get_examination_id"), + path("exam_json_edit", + views.generic_exam_json_edit, + name="generic_exam_json_edit"), ] diff --git a/generic/views.py b/generic/views.py index 9773038d..b6cc64f5 100644 --- a/generic/views.py +++ b/generic/views.py @@ -24,6 +24,13 @@ from .forms import ( from .models import Examination +from rapids.models import Rapid as RapidQuestion +from rapids.models import Exam as RapidExam +from longs.models import Long as LongQuestion +from longs.models import Exam as LongExam +from anatomy.models import AnatomyQuestion as AnatomyQuestion +from anatomy.models import Exam as AnatomyExam + from django.db.models import Case, When @@ -52,6 +59,74 @@ def get_examination_id(request): return HttpResponse(json.dumps(data), content_type="application/json") return HttpResponse("/") +# Generic view to dispatch to indivuals app views +@login_required +def generic_exam_json_edit(request): + if request.is_ajax() and request.method == "POST": + question_type = request.POST.get("type") + + if question_type == "rapid": + Exam = RapidExam + Question = RapidQuestion + elif question_type == "long": + Exam = LongExam + Question = LongQuestion + elif question_type == "anatomy": + Exam = AnatomyExam + Question = AnatomyQuestion + else: + data = {"status": "error"} + return JsonResponse(data, status=400) + + + exam = get_object_or_404(Exam, pk=request.POST.get("exam_id")) + + if "add_exam_questions" in request.POST: + question_ids = json.loads(request.POST.get("add_exam_questions")) + question_objects = Question.objects.filter(pk__in=question_ids) + + exam.exam_questions.add(question_objects) + exam.save() + data = {"status": "success"} + return JsonResponse(data, status=200) + + if "set_open_access" in request.POST: + if request.POST.get("set_open_access") == "true": + state = True + else: + state = False + + questions_changed = [] + for q in exam.exam_questions.all(): + q.open_access = state + q.save() + questions_changed.append(q.pk) + + data = {"status": "success", "questions": questions_changed, "state": state} + return JsonResponse(data, status=200) + + if "set_exam_order" in request.POST: + new_order = json.loads(request.POST.get("set_exam_order")) + + preserved = Case(*[When(pk=pk, then=pos) for pos, pk in enumerate(new_order)]) + objects = Question.objects.filter(pk__in=new_order).order_by(preserved) + + if len(objects) != exam.exam_questions.count(): + data = {"status": "error, count does not match"} + return JsonResponse(data, status=400) + + exam.exam_questions.set(objects) + exam.save() + data = {"status": "success"} + return JsonResponse(data, status=200) + + + data = {"status": "error, unknown request"} + return JsonResponse(data, status=400) + else: + data = {"status": "error"} + return JsonResponse(data, status=400) + class ExamViews(View, LoginRequiredMixin): diff --git a/longs/templates/longs/long_series_viewer.html b/longs/templates/longs/long_series_viewer.html index 88e3196b..bc3d4f94 100755 --- a/longs/templates/longs/long_series_viewer.html +++ b/longs/templates/longs/long_series_viewer.html @@ -1,5 +1,5 @@ -
{{ series.modality}}, {{ series.examination }}
+
{{ series.modality}}, {{ series.examination }}, {{ series.plane }}, {{ series.contrast }}
{% if series.long %} Associated case: @@ -14,7 +14,7 @@ This series is not associated with any cases.
Author: {{ series.get_author_display }}
-Order dicoms by slice location
+Order dicoms by slice location Order by uploaded filename {% for image in series.images.all %} {{image.image.url}}, pos: {{image.position}}, {{image.upload_filename}}
diff --git a/rapids/templates/rapids/view.html b/rapids/templates/rapids/view.html index 234f732c..91e9becf 100755 --- a/rapids/templates/rapids/view.html +++ b/rapids/templates/rapids/view.html @@ -15,14 +15,22 @@ {% render_table table %} + +