.
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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"),
|
||||
]
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
<div>{{ series.modality}}, {{ series.examination }}</div>
|
||||
<div>{{ series.modality}}, {{ series.examination }}, {{ series.plane }}, {{ series.contrast }}</div>
|
||||
|
||||
{% if series.long %}
|
||||
Associated case:
|
||||
@@ -14,7 +14,7 @@ This series is not associated with any cases.
|
||||
|
||||
<div>Author: {{ series.get_author_display }}</div>
|
||||
|
||||
<a href="{% url 'longs:long_series_order_dicom' pk=series.pk %}" title="orders dicom by slice location">Order dicoms by slice location</a> <br/>
|
||||
<a href="{% url 'longs:long_series_order_dicom' pk=series.pk %}" title="orders dicom by slice location">Order dicoms by slice location</a>
|
||||
<a href="{% url 'longs:long_series_order_upload_filename' pk=series.pk %}" title="orders dicom by slice location">Order by uploaded filename</a>
|
||||
{% for image in series.images.all %}
|
||||
{{image.image.url}}, pos: {{image.position}}, {{image.upload_filename}}</br>
|
||||
|
||||
@@ -15,14 +15,22 @@
|
||||
</div>
|
||||
{% render_table table %}
|
||||
|
||||
<button id="button-select-add-exam"></button>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$("#button-select-add-exam").click(function () {
|
||||
// Find selected objects
|
||||
|
||||
|
||||
|
||||
$.ajax({
|
||||
url: "{% url 'rapids:exam_json_edit' pk=exam.pk %}",
|
||||
url: "{% url 'generic:generic_exam_json_edit' %}",
|
||||
data: {
|
||||
csrfmiddlewaretoken: "{{ csrf_token }}",
|
||||
add_exam_questions: true,
|
||||
add_exam_questions: $("table input:checked").serialize(),
|
||||
type: "rapid",
|
||||
exam_id: exam_id,
|
||||
},
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
|
||||
Reference in New Issue
Block a user