diff --git a/rad/urls.py b/rad/urls.py index 0ef32119..3193b4a9 100644 --- a/rad/urls.py +++ b/rad/urls.py @@ -60,6 +60,7 @@ urlpatterns = [ path("feedback/note//complete", views.feedback_mark_complete, name="feedback_mark_complete"), #path("feedback/", views.AddQuestionNote.as_view(), name="feedback"), path("feedback/answer", views.answer_suggestion_submit, name="answer_suggestion_submit"), + path("feedback/answer_submit", views.answer_submit, name="answer_submit"), path("feedback/answer/confirm", views.answer_suggestion_confirm, name="answer_suggestion_confirm"), path("feedback/view", views.view_feedback, name="view_feedback"), diff --git a/rad/views.py b/rad/views.py index 6936bdc9..1ae8df0e 100644 --- a/rad/views.py +++ b/rad/views.py @@ -248,6 +248,37 @@ def answer_suggestion_submit(request): # postExamAnswers return JsonResponse({"success": False, "error": "Invalid data"}) +@login_required +def answer_submit(request): + if request.is_ajax and request.method == "POST": + post_data = json.loads(request.body) + qid = post_data["qid"] + question_type = post_data["question_type"] + answer_string = post_data["answer"] + status = post_data["status"] + + if str(status) not in "012": + return JsonResponse({"success": False, "error": "Invalid status"}) + + if question_type == "anatomy": + AnswerModel = AnatomyAnswer + question = AnatomyQuestion + elif question_type == "rapid": + AnswerModel = RapidAnswer + question = Rapid + else: + return JsonResponse({"success": False, "error": "Invalid question type"}) + + q = get_object_or_404(question, pk=qid) + if AnswerModel.objects.filter(answer=answer_string, question=q): + return JsonResponse({"success": False, "error": "Answer already exists"}) + + + a = AnswerModel(question=q, answer=answer_string, status=status) + a.save() + + return JsonResponse({"success": False, "error": "Invalid data"}) + @login_required def answer_suggestion_confirm(request): if request.is_ajax and request.method == "POST": diff --git a/rapids/models.py b/rapids/models.py index b59f5801..b76ebd0b 100644 --- a/rapids/models.py +++ b/rapids/models.py @@ -312,6 +312,7 @@ class Rapid(models.Model): for r in self.region.all(): for a in self.abnormality.all(): answers.append("{} {}".format(r.name, a.name)) + answers.append("{} {}".format(a.name, r.name)) compare_answers = self.get_compare_answers() diff --git a/rapids/templates/rapids/question_display_block.html b/rapids/templates/rapids/question_display_block.html index e7179ebd..a09ce9b6 100755 --- a/rapids/templates/rapids/question_display_block.html +++ b/rapids/templates/rapids/question_display_block.html @@ -8,17 +8,18 @@

Examination: {{ question.get_examinations }}

Laterality: {{ question.laterality }}

Abnormality: {{ question.get_abnormalities }}

-
Images: +
Images: {% for image in question.images.all %} - Image {{ forloop.counter }}{% if image.feedback_image %} [feedback image]{% endif %}: -
+ Image {{ forloop.counter }}{% if image.feedback_image %} [feedback image]{% endif %}: +
{% endfor %}
Exams: {% for exam in question.exams.all %} - {{ exam.name }}, + {{ exam.name }}, {% endfor %}

Open Access: {{ question.open_access }}

@@ -29,15 +30,16 @@ href="{% url 'rapids:verified_detail' pk=verified.pk %}">{{verified}}, {% endfor %}

Scrapped: {{ question.scrapped }} (toggle)

- Answers (score): {% for answer in question.answers.all %} - - {{ answer }} ({{answer.status}}), - - {% endfor %} + Answers (score): {% for answer in question.answers.all %} + + {{ answer }} ({{answer.status}}), + + {% endfor %}

- + {% if view_feedback %} Notes:
+ + +
+ +

Image viewer

+
+
- + - -

Image viewer

-
- -
+ \ No newline at end of file + // send request to change the is_private state on customSwitches toggle + $(".proposed-answer").each((n, el) => { + + // Add button to confirm answer is correct + $(el).append($("[Correct]").on("click", function () { + $.ajax({ + url: "{% url 'answer_suggestion_confirm' %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + //active: this.checked // true if checked else false + question_type: "rapid", + aid: el.dataset.aid, + status: 2, + }, + type: "POST", + dataType: "json", + }) + // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly + .done(function (data) { + console.log(data); + + if (data.success) { + toastr.info('Answer saved') + $(el).find(".confirm").remove() + $(el).removeClass("proposed-answer") + } + // show some message according to the response. + // For eg. A message box showing that the status has been changed + }) + .always(function () { + console.log('[Done]'); + }) + })) + + // Add button to confirm answer is incorrect + $(el).append($("[Incorrect]").on("click", function () { + $.ajax({ + url: "{% url 'answer_suggestion_confirm' %}", + data: { + csrfmiddlewaretoken: "{{ csrf_token }}", + //active: this.checked // true if checked else false + question_type: "rapid", + aid: el.dataset.aid, + status: 0, + }, + type: "POST", + dataType: "json", + }) + // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly + .done(function (data) { + console.log(data); + + if (data.success) { + toastr.info('Answer saved') + $(el).find(".confirm").remove() + $(el).removeClass("proposed-answer") + } + // show some message according to the response. + // For eg. A message box showing that the status has been changed + }) + .always(function () { + console.log('[Done]'); + }) + })) + }); + }); + + \ No newline at end of file