From 2bdc41278c104a764fea21c61f96989151cc91d6 Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 21 Nov 2021 20:39:08 +0000 Subject: [PATCH] . --- rapids/models.py | 1 + rapids/templates/rapids/rapid_form.html | 27 +++++++++++++++++++++++++ rapids/urls.py | 1 + rapids/views.py | 15 ++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/rapids/models.py b/rapids/models.py index 91acd0bd..d456551e 100644 --- a/rapids/models.py +++ b/rapids/models.py @@ -458,6 +458,7 @@ class RapidImage(models.Model): # Try and read the file as a dicom try: # and generate a hash from the pixel data + # TODO: improve? dataset = pydicom.dcmread(self.image) print(dataset) flatten = dataset.pixel_array.flatten() diff --git a/rapids/templates/rapids/rapid_form.html b/rapids/templates/rapids/rapid_form.html index 690ec725..f4f5196c 100755 --- a/rapids/templates/rapids/rapid_form.html +++ b/rapids/templates/rapids/rapid_form.html @@ -446,6 +446,7 @@ ocr2(url, el); + checkHash(hash); $("#drop-filenames").append( `${n}: ${el.files[0].name}` @@ -468,6 +469,7 @@ let hash = CryptoJS.MD5(pixel_data).toString(); console.log(element, "HASH", hash) + checkHash(hash); }); @@ -630,6 +632,31 @@ } + function checkHash(hash) { + $.ajax({ + url: "{% url 'rapids:rapid_question_by_hash' %}", + data: { + csrfmiddlewaretoken: csrf, + hash: hash + }, + type: "POST", + dataType: "json", + }) + // $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly + .done(function (data) { + console.log(data); + + if (data.status == "success") { + console.log("success"); + console.log(data.id) + toastr.info(f'id {data.id}') + } + }) + .always(function () { + console.log('[Done]'); + }) + } + function extractDicomStudyDescription(byteArray) { // We need to setup a try/catch block because parseDicom will throw an exception // if you attempt to parse a non dicom part 10 file (or one that is corrupted) diff --git a/rapids/urls.py b/rapids/urls.py index 27fe55ec..258def87 100755 --- a/rapids/urls.py +++ b/rapids/urls.py @@ -12,6 +12,7 @@ urlpatterns = [ path("author//", views.GenericViews.author_detail, name="author_detail"), path("author/", views.GenericViews.author_list, name="author_list"), path("question/", views.RapidView.as_view(), name="rapid_view"), + path("question/hash", views.get_question_by_hash, name="rapid_question_by_hash"), # path("unchecked/", views.unchecked_list, name="unchecked_list"), # path("verified//", views.verified_detail, name="verified_detail"), path( diff --git a/rapids/views.py b/rapids/views.py index 079ee59f..621fa068 100755 --- a/rapids/views.py +++ b/rapids/views.py @@ -33,6 +33,7 @@ from .forms import ( from .models import ( Rapid, Abnormality, + RapidImage, Region, Examination, Exam, @@ -1105,3 +1106,17 @@ def question_save_annotation(request, pk): class ExamClone(ExamCloneMixin, ExamCreate): """Clone exam view""" + +@login_required +def get_question_by_hash(request, pk): + if request.is_ajax() and request.method == "POST": + + hash = json.loads(request.POST.get("hash")) + + try: + question = RapidImage.objects.get(image_md5_hash=hash) + data = {"status": "success", "id": question.pk} + return JsonResponse(data, status=200) + except RapidImage.DoesNotExist: + data = {"status": "success", "id": False} + return JsonResponse(data, status=200) \ No newline at end of file